1.
Suppose you have the following series of queue operations.
Queue<String> q = new Queue<>() q.enqueue("hello"); q.enqueue("dog"); q.enqueue("cat"); q.dequeue();
What items are left on the queue (from head to tail)?
- "hello", "dog"
- Remember the first thing added to the queue is the first thing removed. FIFO
- "dog", "cat"
- Yes, first in first out means that "hello" is gone
- "hello", "cat"
- Queues and stacks are both data structures where you can only access the first and the last items.
- "hello", "dog", "cat"
- Ooops, maybe you missed the dequeue call at the end?