You may only operate on the stacks WORK and TEMP, supporting their ADT operations of PUSH (S, X), POP (S, X), and EMPTYSTACK (S), where X is an element or variable to be pushed into or popped out of the stack and S denotes the stack itself. If necessary to complete the procedures, you may also utilise one variable.i i) I How can you determine the least element that was put into Work given n different random numbers? You may employ a single variable. ii) Given n distinct random numbers that are to be pushed into WORK, how can you find the maximum element that was pushed into it, all the while ensuring that the elements stored in WORK are in their descending order with the maximum element beginning at the bottom of stack? You are permitted to use a lone variable and a temporary stack TEMP.
You may only operate on the stacks WORK and TEMP, supporting their ADT operations of PUSH (S, X), POP (S, X), and EMPTYSTACK (S), where X is an element or variable to be pushed into or popped out of the stack and S denotes the stack itself. If necessary to complete the procedures, you may also utilise one variable.i
i) I How can you determine the least element that was put into Work given n different random numbers? You may employ a single variable.
ii) Given n distinct random numbers that are to be pushed into WORK, how can
you find the maximum element that was pushed into it, all the while ensuring that
the elements stored in WORK are in their descending order with the maximum
element beginning at the bottom of stack? You are permitted to use a lone variable
and a temporary stack TEMP.
Step by step
Solved in 2 steps