{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Str &amp; Algorithm HW Solutions 27

# Data Str &amp; Algorithm HW Solutions 27 - if(st == 1...

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

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;
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

{[ snackBarMessage ]}

Ask a homework question - tutors are online