-
Assume that the variable S in the code below has type
stack of integer and that the operators
pop,
push,
empty, and
initialize are properly implemented.
What will the output be if the code is executed?
initialialize(S);
push(S,4);
push(S,2);
push(S,8);
cout << pop(S) << endl;
push(S,5);
push(S,pop(S)+1);
while(not empty(S))
cout << pop(S) << endl;
-
Assume that the variable H in the code below has type
min-heap of integer and that the operators
delete-min,
insert,
empty, and
initialize are properly implemented.
What will the output be if the code is executed?
initialialize(H);
insert(H,3);
insert(H,1);
insert(H,8);
cout << delete-min(H) << endl;
insert(H,4);
insert(H,delete-min(H)+2);
while(not empty(H))
cout << delete-min(H) << endl;
-
In class, I showed how to implement the abstract data type
queue as a circular linked list with a single pointer.
Assume that the variable Q in the code below has type
queue of integer, implemented as a circular linked list,
and all the operators are properly implemented, as shown in class.
Show, by drawing figures, the appearance of the linked list after
each statement in the code below is executed. You should draw five figures.
intialize(Q);
enqueue(Q,5);
enqueue(Q,3);
cout << dequeue(Q) << endl;
enqueue(Q,2);