/********************************************************************************************** * Program Name: queueType.h * Author: Zhixiang Chen * Course: CSCI/CMPE 3333, Fall 14 * Lab 9: Header file for Lab 9-derving array-based queue from array-based list * Date: 08/2014 * Description: This file contains the prototype of the class arrayQueueType * Here, the queue is the FIFO (First In First Out) queue. ************************************************************************************************/ #ifndef H_ArrayQueueType #define H_ArrayQueueType #include #include #include #include "arrayBasedListType.h" using namespace std; //derive arrayStackType from arrayListType template class arrayQueueType: public arrayListType { //overload insertion operator << friend ostream& operator<<(ostream& os, arrayQueueType& x); public: arrayQueueType & operator= // overloading assignment operator ( arrayQueueType&); Type & operator[] (int index); // index operator overloading //two major stack operation Type deQueue(); // enter an element into the queue void enQueue(Type & item); // remove an element from the queue arrayQueueType():arrayListType() // default ructor { front = 0; // front is always at position 0 rear = -1; // rear varies from -1 (empty queue) to count - 1 } arrayQueueType(int n):arrayListType(n)// another ructor { front = 0; // front is always at position 0 rear = -1; // rear varies from -1 (empty queue) to count - 1 } arrayQueueType( arrayQueueType&);// copy ructor ~arrayQueueType(){}; // the destructor private: int front; int rear; void arrayQueueType::copyQueue( arrayQueueType & rhs); //copy stack method }; //deQueue template Type arrayQueueType::deQueue() //remove the front element { assert(!isEmpty()); //make sure the stack is not empty if (!isEmpty()) { Type tmp = list[0]; deleteItem(tmp); return tmp; } else { cout<<"No dequeue, the queue is empty." < void arrayQueueType:: enQueue(Type & item)//push an item upto stack { assert(!isFull()); //make sure no full if(!isFull()) { insertLast(item); rear++; } else { cout<<"No enQueue, the queue is full."< ostream& operator<<<>(ostream& os, arrayQueueType& x) { int flag = 1; for (int i = 0; i < x.length(); i++) { os << x[i] << " "; if (flag %5 == 0) os << endl; flag++; } return os; } // index operator overloading template Type & arrayQueueType::operator[] (int index) { assert(0<= index && index < count); //check the range of the index return list[index]; } // overloading assignment operator template arrayQueueType & arrayQueueType::operator= ( arrayQueueType& rhs) { if (this != & rhs) { copyQueue(rhs); } return *this; } //copy stack template void arrayQueueType::copyQueue( arrayQueueType & rhs) { count = rhs.count; front = rhs.front; rear = rhs.rear; maxSize = rhs.maxSize; delete[] list; if (rhs.isEmpty()) list = NULL; else { list = new Type[maxSize]; for (int i = 0; i arrayQueueType::arrayQueueType( arrayQueueType& rhs) // copy ructor { front = rhs.front; rear = rhs.rear; count = rhs.count; maxSize = rhs.maxSize; delete[] list; if (rhs.isEmpty()) list = NULL; else { list = new Type[maxSize]; for (int i = 0; i