sweet1cris

Untitled

Nov 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class Solution {
  2.     /**
  3.      * @param stack an integer stack
  4.      * @return void
  5.      */
  6.     public void stackSorting(Stack<Integer> stack) {
  7.         Stack<Integer> helpStack = new Stack<Integer>();
  8.         while (!stack.isEmpty()) {
  9.             int element = stack.pop();
  10.             while (!helpStack.isEmpty() && helpStack.peek() < element) {
  11.                 stack.push(helpStack.pop());
  12.             }
  13.             helpStack.push(element);
  14.         }
  15.         while (!helpStack.isEmpty()) {
  16.             stack.push(helpStack.pop());
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment