Created
July 29, 2015 14:32
-
-
Save Alex1990/c859b1fc1548616d76ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var stack1 = []; | |
| var stack2 = []; | |
| function isEmptyStack(stack) { | |
| return stack.length === 0; | |
| } | |
| function enqueue(obj) { | |
| return stack1.push(obj); | |
| } | |
| function dequeue() { | |
| if (!isEmptyStack(stack2)) { | |
| return stack2.pop(); | |
| } else { | |
| return (function transfer() { | |
| if (isEmptyStack(stack1)) { | |
| return stack2.pop(); | |
| } else { | |
| stack2.push(stack1.pop()); | |
| return transfer(); | |
| } | |
| })(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment