linkqueue.h

来自「这是本人精心搜集的关于常用图论算法的一套源码」· C头文件 代码 · 共 49 行

H
49
字号
class Queue
{ public:
     // Standard Queue methods
     Queue ( );
     bool empty( ) const;
     Error_code append(const Queue_entry &item);
     Error_code serve( );
     Error_code retrieve(Queue_entry &item) const;
   // Safety features for linked structures
     ~Queue( );
     Queue(const Queue &original);
     void operator = (const Queue &original);
  protected:
     Node *front, *rear;
};
Queue::Queue( )
/* Post: The Queue is initialized to be empty. */
{   front = rear = NULL;  }
Error_code Queue::append(const Queue entry &item)
/* Post: Add item to the rear of the Queue and return a code 
             of success or return a code of overflow if dynamic 
              memory is exhausted. */
{  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( )
/* Post: The front of the Queue is removed. If the Queue is 
              empty, return an Error_code of underflow. */
{   if (front == NULL) return underflow;
      Node *old_front = front;
      front = old_front->next;
      if (front == NULL) rear = NULL;
      delete old_front;
      return success;
}
class Extended_queue: public Queue
{ public:
    bool full( ) const;
    int size( ) const;
    void clear( );
    Error_code serve_and_retrieve(Queue_entry &item);
};

⌨️ 快捷键说明

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