Beispiel #1
0
 public static void main()
 {
     Stack s = new Stack();
     s.push(19);
     s.push(10);
     s.push(11);
     s.pop();
     s.peek();
 }
 public Stack sort(Stack s)
 {
     while (!s.isEmpty())
     {
         int tmp = s.pop();
         while (!tempStack.isEmpty() && tempStack.peek() > tmp)
         {
             s.push(tempStack.pop());
         }
         tempStack.push(tmp);
     }
     return tempStack;
 }
 public static void main()
 {
     SortedStack sorter = new SortedStack();
     Stack s = new Stack();
     s.push(10);
     s.push(12);
     s.push(4);
     s.push(22);
     s.push(3);
     s.push(153);
     Stack sorted = sorter.sort(s);
     sorter.print(sorted);
 }