Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created October 12, 2021 01:25
Show Gist options
  • Save codecakes/548534760aa5a99f24513b157d92f28a to your computer and use it in GitHub Desktop.
Save codecakes/548534760aa5a99f24513b157d92f28a to your computer and use it in GitHub Desktop.
stack sort
def sort(stack, element):
if not stack or element > stack[-1]:
stack += [element]
else:
top_el = stack.pop()
sort(stack, element)
stack += [top_el]
return stack
def sortStack(stack):
# Write your code here.
if stack:
top_el = stack.pop()
sortStack(stack)
sort(stack, top_el)
return stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment