• 大小: 823KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-01
  • 语言: 其他
  • 标签: Linked  Queue  

资源简介

链式队列是不同于循环数组的另一种队列的实现形式。队列中的元素以Node形式存储。节点Node中存有此节点存于队列中的元素以及指向下一个元素的指针。链式队列的需要保存指向队头和队尾的指针的数据成员。 参见博客:http://blog.csdn.net/xiaowei_cqu/article/details/7748247

资源截图

代码片段和文件信息

#include “linked_queue.h“
#include
using namespace std;

Queue::Queue()
{
front=rear=NULL;
}

bool Queue::empty()const{
if(front==NULL)
return true;
else
return false;
}
Error_code Queue::append(const Queue_entry &item)
{
Node *new_rear = new Node(item);
if(new_rear==NULL)return overflow;
if(rear==NULL)front=rear=new_rear;
else{
rear->next=new_rear;
rear=new_rear;
}
return success;
}

Error_code Queue::serve()
{
if(front==NULL)
return underflow;
Node *old_front=front;
front=old_front->next;
if(front==NULL)
rear=NULL;
delete old_front;
return success;
}

Error_code Queue::retireve(Queue_entry &item)const{
if(empty())
return underflow;
else{
item=front->entry;
return success;
}
}


Queue:: ~Queue()
{
while(!empty())
serve();
}

void Queue::operator =(const Queue &original)
{
Node *new_rear*new_front*new_copy*original_node=original.front;
if(original_node==NULL){
new_front=new_rear=NULL;
}
else{
new_copy=new_front=new Node(original_node->entry);
while(original_node->next!=NULL){
original_node=original_node->next;
new_copy->next=new Node(original_node->entry);
new_copy=new_copy->next;
}
original_node=original.rear;
new_rear=new Node(original_node->entry);
new_rear->next=NULL;
}
while(!empty())
serve();
front=new_front;
rear=new_rear;
}

Queue::Queue(const Queue &original)
{
Node *new_copy*original_node=original.front;
if(original_node==NULL)                              
front=rear=NULL;
else{
front=new_copy=new Node(original_node->entry);
while(original_node->next!=NULL){
original_node=original_node->next;
new_copy->next=new Node(original_node->entry);
new_copy=new_copy->next;
}
original_node=original.rear;
rear=new_copy=new Node(original_node->entry);
}
}


int Extended_queue::size()const
{
Node *window=front;
int count=0;
while(window != NULL){
window=window->next;
count++;
}

return count;
}

void Extended_queue::clear()
{
while(!empty())
serve();
}
Error_code Extended_queue::serve_and_retrieve(Queue_entry &item)
{
if(front==NULL)
return underflow;
Node *old_front=front;
front=old_front->next;
item=old_front->entry;
if(front==NULL)rear=NULL;
delete old_front;
return success;
}



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-07-14 17:24  polynomial\
     目录           0  2012-07-14 17:24  polynomial\Debug\
     文件       47104  2010-04-06 14:32  polynomial\Debug\polynomial.exe
     文件      525732  2010-04-06 14:32  polynomial\Debug\polynomial.ilk
     文件      642048  2010-04-06 14:32  polynomial\Debug\polynomial.pdb
     目录           0  2012-07-14 17:24  polynomial\polynomial\
     文件     1682432  2010-04-06 15:43  polynomial\polynomial.ncb
     文件         896  2010-03-29 23:53  polynomial\polynomial.sln
     文件       26624  2010-04-06 15:43  polynomial\polynomial.suo
     目录           0  2012-07-14 17:24  polynomial\polynomial\Debug\
     文件        7162  2010-04-06 14:32  polynomial\polynomial\Debug\BuildLog.htm
     文件       35846  2010-03-30 13:22  polynomial\polynomial\Debug\linked_queue.obj
     文件          69  2010-04-06 14:32  polynomial\polynomial\Debug\mt.dep
     文件       23933  2010-03-30 00:28  polynomial\polynomial\Debug\node.obj
     文件         663  2010-03-30 00:33  polynomial\polynomial\Debug\polynomial.exe.embed.manifest
     文件         728  2010-03-30 00:33  polynomial\polynomial\Debug\polynomial.exe.embed.manifest.res
     文件         621  2010-04-06 14:32  polynomial\polynomial\Debug\polynomial.exe.intermediate.manifest
     文件       55860  2010-03-30 13:24  polynomial\polynomial\Debug\polynomial.obj
     文件        2693  2010-03-30 00:28  polynomial\polynomial\Debug\term.obj
     文件       46864  2010-04-06 14:32  polynomial\polynomial\Debug\try_polynomial.obj
     文件      248832  2010-04-06 14:32  polynomial\polynomial\Debug\vc90.idb
     文件      225280  2010-04-06 14:32  polynomial\polynomial\Debug\vc90.pdb
     文件        2375  2010-03-30 13:22  polynomial\polynomial\linked_queue.cpp
     文件         581  2010-03-30 00:53  polynomial\polynomial\linked_queue.h
     文件         136  2010-03-30 00:22  polynomial\polynomial\node.cpp
     文件         317  2010-03-30 00:28  polynomial\polynomial\node.h
     文件        2456  2010-03-30 13:24  polynomial\polynomial\polynomial.cpp
     文件         420  2010-04-06 15:43  polynomial\polynomial\polynomial.h
     文件        4450  2010-03-30 00:33  polynomial\polynomial\polynomial.vcproj
     文件        1427  2010-04-06 15:43  polynomial\polynomial\polynomial.vcproj.PC2010031614HZV.Administrator.user
     文件         109  2010-03-30 00:28  polynomial\polynomial\term.cpp
............此处省略2个文件信息

评论

共有 条评论