Question: Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to write this program: push | pop | peek | isEmpty.
package CareerCup;
public class SortStack
{
public SortStack(){}
public Stack sort(Stack s)
{
Stack r = new Stack();
while(!s.empty())
{
Node node = s.pop();
int tmp = node.data;
while(!r.empty() && r.peek()>tmp)
s.push(r.pop().data);
r.push(tmp);
}
return r;
}
}