Created
July 2, 2014 05:28
-
-
Save ryancooper/fd37ad761c15da4c95d4 to your computer and use it in GitHub Desktop.
Stack sort in python(using system stack)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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