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

📄 c07p354.txt

📁 Data Abstraction & Problem Solving with C++源码
💻 TXT
字号:
// ********************************************************// Implementation file QueueA.cpp for the ADT queue.// Circular array-based implementation.// The array has indexes to the front and back of the// queue. A counter tracks the number of items currently// in the queue.// ********************************************************#include "QueueA.h"  // header fileQueue::Queue():front(0), back(MAX_QUEUE-1), count(0){}  // end default constructorbool Queue::isEmpty() const{   return count == 0);}  // end isEmptyvoid Queue::enqueue(QueueItemType newItem) throw(QueueException){   if (count == MAX_QUEUE)      throw QueueException("QueueException: queue full on enqueue");   else   {  // queue is not full; insert item      back = (back+1) % MAX_QUEUE;      items[back] = newItem;      ++count;   }  // end if}  // end enqueuevoid Queue::dequeue() throw(QueueException){   if (isEmpty())      throw QueueException("QueueException: empty queue, cannot dequeue");   else   {  // queue is not empty; remove front      front = (front+1) % MAX_QUEUE;      --count;   }  // end if}  // end dequeuevoid Queue::dequeue(QueueItemType& queueFront) throw(QueueException){   if (isEmpty())      throw QueueException("QueueException: empty queue, cannot dequeue");   else   {  // queue is not empty; retrieve and remove front      queueFront = items[front];      front = (front+1) % MAX_QUEUE;      --count;   }  // end if}  // end dequeuevoid Queue::getFront(QueueItemType& queueFront) const                     throw(QueueException){   if (isEmpty())      throw QueueException("QueueException: empty queue, cannot getFront");   else      // queue is not empty; retrieve front      queueFront = items[front];}  // end getFront// End of implementation file.

⌨️ 快捷键说明

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