Skip to content

Instantly share code, notes, and snippets.

@ryancooper
Created July 2, 2014 05: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 ryancooper/fd37ad761c15da4c95d4 to your computer and use it in GitHub Desktop.
Save ryancooper/fd37ad761c15da4c95d4 to your computer and use it in GitHub Desktop.
Stack sort in python(using system stack)
def stackInsert(stack, elem):
if len(stack) == 0 or stack[len(stack)-1] <= elem:
stack.append(elem)
else:
topElem = stack.pop()
stackInsert(stack, elem)
stack.append(topElem)
def stackSort(stack):
if len(stack) == 0:
return
elem = stack.pop()
stackSort(stack)
stackInsert(stack, elem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment