Data Str & Algorithm HW Solutions 27

Data Str & Algorithm HW Solutions 27 - if (st == 1)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
27 ˜AStack2() { delete [] listArray; } // Destructor void clear(int st) { if (st == 1) top1 = 0; else top2 = size - 1; if (top1+1 >= top2) return false; // Stack is full if (st == 1) listarray[top1++] = item; else listarraay[top2--] = item; return true; } // Pop top element if ((st == 1) & (top1 == 0)) return false; if ((st == 2) & (top2 == (size-1))) return false; if (st == 1) it = listArray[--top1]; else it = listArray[++top2]; return true; } if ((st == 1) & (top1 == 0)) return false; if ((st == 2) & (top2 == (size-1))) return false;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (st == 1) it = listArray[top1-1]; else it = listArray[top2+1]; return true; } int length(int st) const { if (st == 1) return top1; else return size - top2 - 1; } }; 4.13 // Array-based queue implementation template <class Elem> class AQueue: public Queue<Elem> { private: int size; // Maximum size of queue int front; // Index of front element int rear; // Index of rear element Elem *listArray; // Array holding queue elements bool isEmpty; public: AQueue(int sz =DefaultListSize) { // Constructor // Make list array one unit larger for empty slot size = sz+1; rear = 0; front = 1;...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online