Question: Problem Statement Given the stack interface discussed in the class, add a new method called moveSmallestToTop to it. This method will determine which value in





Problem Statement Given the stack interface discussed in the class, add a new method called moveSmallestToTop to it. This method will determine which value in the stack is the smallest and move that value to the top of the stack while otherwise leaving the remainder of the stack in its original order. This java code returns nothing. For example, suppose myStack contains the integer values (bottom 4 2 8 3 6 5 top), then a call to moveSmallestToTop (stack1) would leave myStack as follows: (bottom 4 8 3 6 5 2 top). In your solution, you may only declare extra stack called tempStack, which is a Java Collections Framework Class Stack, or scalar variables (e.g., ints, - not arrays or linked lists allowed). 1. The interface for myStack is given below: pubic interface stacklnterfacel public boolean isEmpty):// return true if stack is empty, false otherwise. public void popAll()://remove all items from the stack. public void push(Object newltem); //Add newltem to the top of the stack /You can assume that any stack (myStack) you use will never become full so you need /ot to throw an exception and that the provided stack will not contain duplicate //values public object pop() throws StackException://removes the top of a stack //if the stack is empty, throw StackException. public object peek() throws StackException;// retrieves the top of a stack //if the stack is empty, throw StackException public static void moveSmallestToTop(StackReferenceBased myStack); //end Stacklnterface The implementation of the LinkedList based is given below: Public class stackReferenceBased implements Stacklnterface private Node top; public StackReferenceBased() top null; I//end constructor public boolean isEmpty()0 return top null; //end isEmpty public void push (Object newltem) top new Node(newltem, top); // end push Public Object pop throws StackException { If(!isEmpt)) Node temp-top; top-top.next; return temp.item; else throw new StackException("StackExceptio on"+"pop: stack empty"); //end if //end pop public void popAlIO top -null; /end popAI public Object peek() throws StackException f if(!isEmpty()) return top.item else throw new StackException("StackException on "+"peek: stack empty"; //end if //end peek //end StackReferenceBased public static void moveSmallestToTop(StackReferenceBased myStack)i if(myStack.isEmpty) Stack tempStack-new Stack(); // Add vour code here You also need the StackException class as below public class stackException extends java.lang.RuntimeExceptionf public StackException(String s) super(s); //end constructor //end StackException Node class public class Node private T item; private Node next; public Node(l item null; next-null; public Node(T newltem) item-newltem next-null; //end of constructor public Node(T newltem, Node nextNode)f item-newltem; next-nextNode; //end of constructor public void setltem(T newltem) item-newltem; public void setNext(Node newNode)i next-newNode; public T getltem(A return item; public Node getNext()i return next; Problem Statement Given the stack interface discussed in the class, add a new method called moveSmallestToTop to it. This method will determine which value in the stack is the smallest and move that value to the top of the stack while otherwise leaving the remainder of the stack in its original order. This java code returns nothing. For example, suppose myStack contains the integer values (bottom 4 2 8 3 6 5 top), then a call to moveSmallestToTop (stack1) would leave myStack as follows: (bottom 4 8 3 6 5 2 top). In your solution, you may only declare extra stack called tempStack, which is a Java Collections Framework Class Stack, or scalar variables (e.g., ints, - not arrays or linked lists allowed). 1. The interface for myStack is given below: pubic interface stacklnterfacel public boolean isEmpty):// return true if stack is empty, false otherwise. public void popAll()://remove all items from the stack. public void push(Object newltem); //Add newltem to the top of the stack /You can assume that any stack (myStack) you use will never become full so you need /ot to throw an exception and that the provided stack will not contain duplicate //values public object pop() throws StackException://removes the top of a stack //if the stack is empty, throw StackException. public object peek() throws StackException;// retrieves the top of a stack //if the stack is empty, throw StackException public static void moveSmallestToTop(StackReferenceBased myStack); //end Stacklnterface The implementation of the LinkedList based is given below: Public class stackReferenceBased implements Stacklnterface private Node top; public StackReferenceBased() top null; I//end constructor public boolean isEmpty()0 return top null; //end isEmpty public void push (Object newltem) top new Node(newltem, top); // end push Public Object pop throws StackException { If(!isEmpt)) Node temp-top; top-top.next; return temp.item; else throw new StackException("StackExceptio on"+"pop: stack empty"); //end if //end pop public void popAlIO top -null; /end popAI public Object peek() throws StackException f if(!isEmpty()) return top.item else throw new StackException("StackException on "+"peek: stack empty"; //end if //end peek //end StackReferenceBased public static void moveSmallestToTop(StackReferenceBased myStack)i if(myStack.isEmpty) Stack tempStack-new Stack(); // Add vour code here You also need the StackException class as below public class stackException extends java.lang.RuntimeExceptionf public StackException(String s) super(s); //end constructor //end StackException Node class public class Node private T item; private Node next; public Node(l item null; next-null; public Node(T newltem) item-newltem next-null; //end of constructor public Node(T newltem, Node nextNode)f item-newltem; next-nextNode; //end of constructor public void setltem(T newltem) item-newltem; public void setNext(Node newNode)i next-newNode; public T getltem(A return item; public Node getNext()i return next