//CIS 610-251: Queue and LinkList //Due OCt 14,1999 //Assignment # 4, Question # 2. //Object: Que of Stack #include #include "stack.h" #define MAX 5 class Queue { private: Stack * queue; int rear,front; public: Stack Remove(void); bool Insert(Stack); void Empty(); bool isEmpty(); Queue(); }; Queue::Queue() { queue=new Stack[MAX]; rear=front=0;//front } //EnQueue an integer n. Successful insertion return true; bool Queue::Insert(Stack s) { if (rear==MAX-1) { if (front==0) return false; else rear=0;queue[rear]=s; } else { if (rear+1 == front) return false; else { rear++; queue[rear]=s; } } return true; } //DeQueue an integer and return it. Stack Queue::Remove() { if (!isEmpty()) { if(front==MAX-1) { front=0; return queue[front]; } else { front++; return queue[front]; } } return NULL; } //true if Queue is Empty bool Queue::isEmpty(void) { return (front==rear)? true : false; } //render queue empty void Queue::Empty(void) { front=rear=0; } //Main Program loop starts here main() { Queue q; Stack s,s2; s.push(1); s.push(3); q.Insert(s); s.push(2); s.push(4); q.Insert(s); s2=q.Remove(); cout << s2.pop(); s2=q.Remove(); cout << s2.pop(); return 0; }