【正文】
Advance Data Structure Review of Chapter 3 張啟中 Queue ? Queue ? An ordered list ? All insertions take place at one end, rear ? All deletions take place at the opposite end, front ? FirstInFirstOut (FIFO) Abstract Data Type for Queue template class KeyType class Queue { //objects: a finite ordered list with zero or more elements. public: Queue(int MaxQueueSize=DefaultSize)。 //create an empty queue whose maximum size is MaxQueueSize Boolean IsFullQ()。 //if (number of elements in queue== MaxQueueSize) return TRUE //else return FALSE void Add(const Keytypeamp。 item)。 //if (IsFullQ()) then QueueFull() //else insert item at rear of queue Boolean IsEmptyQ()。 //if number of elements in the queue is equal to 0 then return TRUE //else return FALSE Keytype* Delete(KeyTypeamp。)。 //if (IsEmpty()) then QueueEmpty() and return 0 //else remove the item at front of queue and return a pointer to it }。 Representation: Queue ? Definition private: int front, rear。 KeyType *queue。 int MaxSize。 ? Implementation of Queue template class KeyType QueueKeyType::Queue(int MaxQueueSize):MaxSize(MaxQueueSize) { queue = new Keytype[MaxSize]。 front = rear = 1。 } Queue 的操作 ? Implementation of member function IsFull() ? Implementation of member function IsEmpty() ? Implementation of member function Add() ? Implementation of member function Del