Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortStack(stack){
- var sortedStack = new Stack ();
- while (!stack.isEmpty()){
- var curr = stack.pop();
- while (!sortedStack.isEmpty() && sortedStack.peek().data > curr.data){
- stack.push(sortedStack.pop().data);
- }
- sortedStack.push(curr.data);
- }
- while (!sortedStack.isEmpty()){
- stack.push(sortedStack.pop().data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement