Question: Please do in java. Please provide code and screenshot. Will give thumbs up import java.util.Deque; import java.util.ArrayDeque; class Tester { public static Deque changeSmallest(Deque inputStack)

Please do in java. Please provide code and screenshot. Will give thumbs up Please do in java. Please provide code and screenshot. Will give thumbs

import java.util.Deque; import java.util.ArrayDeque;

class Tester { public static Deque changeSmallest(Deque inputStack) { public static Deque updateStack(Deque inputStack) { //Implement your logic here and change the return statement accordingly Deque temporaryStack = new ArrayDeque (); //create a temporary stack while(!inputStack.isEmpty()){ //pop chars from inputStack and push into temporaryStack temporaryStack.push(inputStack.pop()); } //pop bottom four elements which are on top of temporaryStack char bottom3 = temporaryStack.pop(); char bottom5 = temporaryStack.pop();

while(!temporaryStack.isEmpty()){ //pop remaining chars from temporaryStack and push into inputStack inputStack.push(temporaryStack.pop()); } inputStack.push(bottom3); //push the bottom three elements on the inputStack inputStack.push(bottom5); return inputStack; //return the inputStack } }

public static void main(String[] args) { Deque inputStack = new ArrayDeque(); inputStack.push(10); inputStack.push(8); inputStack.push(5); inputStack.push(12); inputStack.push(5); Deque updatedStack = changeSmallest(inputStack); System.out.println("Stack After Modification:"); for (Integer value : updatedStack) System.out.println(value); } }

Problem Statement Implement a program to update a given input stack such that all occurrences of the smallest value are at the bottom of the stack while the order of the other elements remain the same. Implement the logic inside changeSmallest() method. Test the functionalities using the main() method of the Tester class. Sample Input and Output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!