CJCoding With Joseph
15free / daySign inCreate account

Peek at the Front of a Linked Queue

LinkedQueue is complete except for peek(), the method that looks at the front of the queue without removing anything.

Requirements:
1. Return -1 when the queue is empty.
2. Otherwise return the value stored in the head node.
3. Leave head, tail and size untouched - two peeks in a row must give the same answer.

The Node class is provided - do not rename it and do not add public to it, because a Java source file may contain only one public class.

Do NOT write a main method.

Expected Output:

5
5
3
5 -> 6 -> 7 -> null
6

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Data Structures & AlgorithmsQueues
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.