Question: Paliw 9/10 OW me 21. (16 marks) Given a stack s storing n intoger values and an integer value x, write an algorithm inStack(x) that
Paliw 9/10 OW me 21. (16 marks) Given a stack s storing n intoger values and an integer value x, write an algorithm inStack(x) that returns true if x is in the stack and it returns false otherwise. After the exe- cution of the algorithms must be exactly as it was before the algorithm was executed, i.e. it must have the same values and in the same positions. Your algorithm can use one additional stack as auxiliary data structure. You cannot use any other additional data structures. Write auxStack - new stack to create an empty stack, and use methods push, pop, and isEmpty to manipulate a stack. You CANNOT assume that the stack is implemented using an array, singly linked list, doubly linked list, or other data structure. The only way to manipulate the stacks is through the use of the above operations. Assume that s is an instance variable. I Hint. Move the values in s to the auxiliary stack so you can compare them with x. Remember that before the algorithm terminates all values must be put back in s. For the following two questions write algorithms in Java or in detailed Java-like pseudocode like the one used in the lecture notes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
