The java code below is a simple implementation of an array based data structure that is either a stack or a queue. What type of structure is this, and how should the three methods one(), two(), and three() be renamed so that they describe their functions?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Suppose the following operations are made on a circular queue structure.
After completing these operations, what are the remaining items in the queue?
The code below makes use of a deque object. A deque object is similar to a queue except that it allows the insertion/deletion of an element to both the back and front of the queue. What does the pseudocode below output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
The addRear(e)
method adds an item to the rear of a deque,the addFront(e)
to the front and removeFront()
and removeRear()
remove the front and rear items of a deque respectively.
Which of the following best represents a queue data structure?
A) A pile of dirty dishes requiring washing
B) Requests on a single shared resource, like a printer
C) A line of people waiting to go to an amusement park ride
D) (B) and (C)
The below is incomplete python code to implement a queue that uses only two int variables(self.size and self.val) to save its contents.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
However, this queue only supports single digit integers as elements. Specifically, the only elements that can be pushed to the queue are numbers in the range to . The dequeue()
method of the queue class is incomplete. Which of the following methods correctly implements the dequeue()
method?
A
1 2 3 4 5 6 |
|
B
1 2 3 4 5 |
|
C
1 2 3 4 5 |
|
D
1 2 3 4 5 |
|