In: Computer Science
#data structures
Assume you are given an implementation of the Stack class. Recall
that it has methods push(), pop(), top(), isEmpty() and isFull().
Write an Integer function with prototype:
public static Integer popBottom(Stack<Integer> stk);
Note that it has one parameter, a single stack object stk. The
function should delete the item at the bottom of the stack and
return this item as the value of the function. If the stack is
empty return null. When the function returns the stk should not
otherwise be changed. You may not use arrays or queues – only Stack
objects, Integer objects or ints. Make no assumptions about the
implementation details of the stack object.
The logic and the function is as follows where we create a dummy stack and push the values and then we return the top value in dummy stack and then we push the elements back to the original stack.