Skip to content

Instantly share code, notes, and snippets.

@aniruddha84
Created March 9, 2016 22:04
Show Gist options
  • Save aniruddha84/e54753e1dc3790ffbf3c to your computer and use it in GitHub Desktop.
Save aniruddha84/e54753e1dc3790ffbf3c to your computer and use it in GitHub Desktop.
Sort a stack of integers
def stack_sort(stack)
result = []
until stack.empty?
t = stack.pop
while !result.empty? && result.last > t
stack.push result.pop
end
result.push t
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment