import java.util.*;
class Main {
public static Stack<Integer> sortStack(Stack<Integer> input) {
Stack<Integer> tempStack = new Stack<Integer>();
while (!input.isEmpty()) {
int temp = input.pop();
while (!tempStack.isEmpty() && tempStack.peek() > temp) {
input.push(tempStack.pop());
}
tempStack.push(temp);
}
return tempStack;
}
// Driver Code
public static void main(String args[]) {
Stack<Integer> input = new Stack<Integer>();
Scanner s = new Scanner(System.in);
String name = s.nextLine();
System.out.println(name);
String[] nameArr = name.split(" ");
for(int i=0; i<nameArr.length; i++){
input.add(Integer.parseInt(nameArr[i]));
}
Stack<Integer> tmpStack = sortStack(input);
while (!tmpStack.empty()) {
System.out.print(tmpStack.pop() + " ");
}
s.close();
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: