【正文】
2 3 4 5 6 7 front Rear Queue Implementation II: Circular Array template class KeyType QueueKeyType::Queue(void):MaxSize(MaxQueueSize) { queue = new KeyType[MaxSize]。x。 } Queue Implementation I: Linear Array MaxSize 1 front = 1 …… 0 1 2 3 4 rear = 3 delete template class KeyType KeyType* QueueKeyType::Delete() { if (isEmpty()) { QueueEmpty()。 front = rear = 1。 Representation: Queue ? Definition private: int front, rear。 //if (IsFullQ()) then QueueFull() //else insert item at rear of queue Boolean IsEmptyQ()。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)。 item)。 //if (IsEmpty()) then QueueEmpty() and return 0 //else remove the item at front of queue and return a pointer to it }。 ? Implementation of Queue template class KeyType QueueKeyType::Queue(int MaxQueueSize):MaxSize(MaxQueueSize) { queue = new Keytype[MaxSize]。 else queue[++rear] = x。 return amp。 ?所謂的環(huán)形陣列,是一個普通的陣列,但 在概念上將其首尾相接而成 。因為 front == rear 時 Queue 可能為空,也可能為滿。 else queue[rear=newrear]=x。 } front = (front+1) % MaxSize。