SHARE
TWEET

Untitled

a guest Jul 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sortStack(stack){
  2.   var sortedStack = new Stack ();
  3.  
  4.   while (!stack.isEmpty()){
  5.  
  6.     var curr = stack.pop();
  7.  
  8.     while (!sortedStack.isEmpty() && sortedStack.peek().data > curr.data){
  9.       stack.push(sortedStack.pop().data);
  10.     }
  11.     sortedStack.push(curr.data);
  12.  
  13.   }
  14.  
  15.   while (!sortedStack.isEmpty()){
  16.     stack.push(sortedStack.pop().data);
  17.   }
  18.  
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top