Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Created July 29, 2015 14:32
Show Gist options
  • Select an option

  • Save Alex1990/c859b1fc1548616d76ff to your computer and use it in GitHub Desktop.

Select an option

Save Alex1990/c859b1fc1548616d76ff to your computer and use it in GitHub Desktop.
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