Question: Q 2 ) ( a ) Write a function: reverseStack ( Stack st ) , which prints the contents of the stack st in reverse
Qa Write a function: reverseStackStack st which prints the contents of the stack st in reverse ie the top of the stack is printed last
You are allowed only to use another stack, Stack st That is you cannot use any arrays etc. The only functions you can use on stacks are pop push and emptyHint: You put the contents of one stack into another by popping and pushing. Is the order the same?
b Let n be the length of the input stack. Let k be the total number of times you had to push and pop from the two stacks. Express k in terms of n What is the complexity of this reversing algorithm in Onotation?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
