Created
October 12, 2021 01:25
-
-
Save codecakes/548534760aa5a99f24513b157d92f28a to your computer and use it in GitHub Desktop.
stack sort
This file contains hidden or 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 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