Solution Review: Reversing First "k" Elements of Queue
This review provides a detailed analysis to help you solve the "Reversing First "k" Elements of Queue" challenge.
We'll cover the following...
We'll cover the following...
Solution: Using a queue #
Take a look at the algorithm step-by-step:
-
Check if the queue is empty (line 14). If it is not, start by creating a
stack. The available stack functions are:- Constructor:
myStack() - Push elements:
push(int)to add elements to the stack - Pop elements:
pop()to remove or pop the top element from the stack. - Check if empty:
isEmpty()returns true if the stack is empty and false otherwise. - Return top:
getTop()function returns the top element (that has been added at the end) without removing it from the stack.
- Constructor:
-
The function
reverseK(queue, k)takes ...