(a) Be sure to label which end is the top and which is the bottom
S = NewStack(); Push(S,5); Push(S,Top(S)+3); Push(S,6); Pop(S); Push(S,9); Push(S,Pop(S)-2); Push(S,0);
(b) Be sure to indicate which end is the front and which is the back
Q = NewQueue(); Enqueue(Q,5); Enqueue(Q,0); Enqueue(Q,1); Dequeue(Q); Enqueue(Q,3); Enqueue(Q,Front(Q)+5); Enqueue(Q,Dequeue(Q)); Enqueue(Q,Front(Q)); Enqueue(Q,Dequeue(Q)+1); Enqueue(Q,5);
(c) Use lazy deletion
T = New Tree(); Insert(T,5); Insert(T,9); Insert(T,7); Delete(T,5); Insert(T,11); Insert(T,3); Insert(T,4); Insert(T,1); Delete(T,3);
(d) Repeat (c), but delete by replacing the value with its largest left descendent
C C++ -------------------------- ------------------------- typedef struct _TreeNode { /* TreeNode defined as in C */ int data; struct _TreeNode *Left; class List { struct _TreeNode *Right; private: } TreeNode; TreeNode *root; ... typedef TreeNode *Tree; }
10 / \ 5 13 / / \ 1 11 15 \ \ 3 17