{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Str &amp; Algorithm HW Solutions 28

# Data Str &amp; Algorithm HW Solutions 28 - return true...

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

28 Chap. 4 Lists, Stacks, and Queues listArray = new Elem[size]; isEmpty = true; } ˜AQueue() { delete [] listArray; } // Destructor void clear() { front = rear; isEmpty = true; } bool enqueue(const Elem& it) { if ((isEmpty != true) && (((rear+1) % size) == front)) return false; rear = (rear+1) % size; // Circular increment listArray[rear] = it; isEmpty = false; return true; } bool dequeue(Elem& it) { if (isEmpty == true) return false; // Empty it = listArray[front]; front = (front+1) % size; // Circular increment if (((rear+1) % size) == front) isEmpty == true;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return true; } bool frontValue(Elem& it) const { if (isEmpty == true) return false; // Empty it = listArray[front]; return true; } virtual int length() const { if (isEmpty == true) return 0; return ((rear+size) - front + 1) % size; } }; 4.14 bool palin() { Stack<char> S; Queue<char> Q; while ((c = getc()) != ENDOFSTRING) { S.push(c); Q.enqueue(c); } while (!S.isEmpty()) { if (S.top() != Q.front()) return FALSE; char dum = S.pop(); dum = Q.dequeue(); } return TRUE;...
View Full Document

{[ snackBarMessage ]}