Implement a method which takes three Stacks Stack allInput, evenOutput, OddOutpu
ID: 3600596 • Letter: I
Question
Implement a method which takes three Stacks Stack allInput, evenOutput, OddOutput object. The method pops each element from the stack allInput . If the element is even, it pushes the element in evenOutput stack, otherwise, in oddOutput stack. allInput stack should be empty after the operation.
• Implement another method which performs the same operation, but instead of three stacks, it takes three queues as parameters <<<<<<<<<<< Just this
IN JAVA PLZ
you could write it in psudocode or just code is fine.
Explanation / Answer
PSEUDOCODE
Algorithm StackOperation(Stack allInput , Stack evenOutput, Stack OddOutput)
START
while (! allInput.isEmpty())
val = allInput.pop()
if val%2 ==0
evenOutput.push(val)
else
OddOutput.push(val)
END
Algorithm QueueOperation(Queue allInput , Queue evenOutput, Queue OddOutput)
START
while (! allInput.isEmpty())
val = allInput.dequeue()
if val%2 ==0
evenOutput.enqueue(val)
else
OddOutput.enqueue(val)
END
Thanks, let me know if there is any concern.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.