📄 linkqueue.h
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -