Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement