⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.h

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 H
字号:
//顺序循环队列的模板类接口定义以及基本运算的实现代码
#include<iostream.h>
enum Error_code{ success, overflow, underflow };
const int_maxqueue = 10; // small value for testing
class Queue
{ public:
    Queue( );
    bool empty( ) const;
    Error_code serve( );
    Error_code append(const Queue_entry &item);
    Error_code retrieve(Queue_entry &item) const;
  protected:
    int count;
    int front, rear;
    Queue_entry entry[maxqueue];
};

Queue::Queue( )
// Post: TheQueue is initialized to be empty. 
{ count=0;
  rear=maxqueue-1;
  front=0;
}
bool Queue::empty( ) const
// Post: Returntrue if theQueue is empty, otherwise return false. 
{ return count==0;  }

Error_code Queue::append(const Queue_entry &item)
// Post: item is added to the rear of the Queue . If the Queue is full return an
// Error_code of overflow and leave the Queue unchanged.
{ if(count>=maxqueue) return overflow;
  count++;
  rear=((rear+1)==maxqueue)? 0: (rear+1);
  entry[rear]=item;
  return success;
}
Error_code Queue::serve( )
// Post: The front of the Queue is removed. If the Queue is empty return an Error code ofunderflow.
{ if(count<=0) return underflow;
  count--;
  front=((front+1)==maxqueue)? 0 : (front+1);
  return success;
}
Error_code Queue::retrieve(Queue_entry &item) const
// Post: The front of theQueue retrieved to the output parameteritem . If theQueue is empty return anError_code ofunderflow.
{
 if(count<=0) return underflow;
 item = entry[front];
 return success;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -