Skip to content

Instantly share code, notes, and snippets.

@thomasvaeth
Created May 7, 2018 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasvaeth/c5b4cafe9a778a00116fa3dadad09ca4 to your computer and use it in GitHub Desktop.
Save thomasvaeth/c5b4cafe9a778a00116fa3dadad09ca4 to your computer and use it in GitHub Desktop.
"Opinion is the medium between knowledge and ignorance." - Plato
function sortWithStack(arr) {
var stack = [],
current = null;
while (arr.length) {
current = arr.pop();
while (stack.length && stack[stack.length - 1] > current) {
arr.push(stack.pop());
}
stack.push(current);
}
return stack;
}
sortWithStack([1, 3, 5, 4, 2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment