Exercises from Chapter 4 4.14 4.19 4.20 Solutions 4.14 bool palin() { Stack S; Queue 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; 4.19 As we will learn, using certain kinds of binary tree structures will permit both insert and find operations to run in time Theta(log n). 4.20 (a) bool balance(String str) { Stack S; int pos = 0; while (str.charAt(pos) != NULL) { if (str.charAt(pos++) == '(') S.push('('); else if (str.charAt(pos++) == ')') if (S.isEmpty()) return FALSE; else S.pop(); } if (S.isEmpty()) return TRUE; else return FALSE; } (b) int balance(String str) { Stack S; int pos = 0; while (str.charAt(pos) != NULL) { if (str.charAt(pos++) == '(') S.push(pos); else if (str.charAt(pos++) == ')') if (S.isEmpty()) return pos; else S.pop(); } if (S.isEmpty()) return -1; else return S.pop(); }