Diagrams and Recursion
Select the best answer:
At the start of a lab, students download the lab handout and source code files from cuLearn. Which of
the following collections should the cuLearn server software use to ensure that download requests are
processed in the same order in which they are received?
! A stack.
! A queue.
! A list.
Which of the following collections would be the best choice when designing the software that
implements the "undo" operation in a text editor.
! A stack.
! A queue.
! A list.
In two labs, you implemented a list collection that used a dynamically allocated array as the underlying
data structure. Could this collection be redesigned to use a circular, singly-linked list as its underlying
data structure? (Recall that, in another lab, you used this type of linked list to implement a queue.)
! Yes
! No
A stack's pop operation:
! Inserts an item at the bottom of the stack.
! Inserts an item at the top of the stack.
! Inserts an item at the specified position in the stack
! Returns the item at the top of the stack, but doesn't modify the stack.
! Returns the item at the bottom of the stack, but doesn't modify the stack.
! Returns the item at the specified position in the stack, but doesn't modify the stack.
! Removes and returns the item at the top of the stack.
! Removes and returns the item at the bottom of the stack.
! Removes and returns the item at the specified position in the stack.
Page 1 of 16
, SYSC 2006 Sample Exam Questions: Pointers, Arrays, Stacks, Queues, and Linked Lists, plus Memory
Diagrams and Recursion
Suppose s points to a stack that stores integers. Functions that provide push, peek and pop operations
have been defined. The following statements are executed, starting with an empty stack:
push(s, 10);
push(s, 20);
push(s, 30);
int i = peek(s);
int j = pop(s);
push(s, 40);
int k = pop(s);
int m = pop(s);
What is the value of m after these statements are executed?
! 10
! 20
! 30
! 40
! None of the above.
Suppose q points to a queue that stores integers. Functions that provide enqueue, dequeue and front
operations have been defined. The following statements are executed, starting with an empty queue:
enqueue(q, 10);
enqueue(q, 20);
enqueue(q, 30);
int w = dequeue(q);
int x = front(q);
enqueue(q, 40);
int y = dequeue(q);
int z = dequeue(q);
What is the value of z after these statements are executed?
! 10
! 20
! 30
! 40
! None of the above.
Page 2 of 16