Created
June 10, 2022 13:57
-
-
Save eitozx/65f4112b54f1b27f92d3f6ea3eb73072 to your computer and use it in GitHub Desktop.
Push, Pop & Display Operations for 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
stack = [] | |
top = None if stack == [] else len(stack) - 1 | |
def push(stack, element): | |
stack.append(element) | |
global top | |
top = len(stack) - 1 | |
return stack # optional | |
def pop(stack): | |
if len(stack) == 0: | |
return "Underflow" | |
else: | |
stack.pop() | |
global top | |
top = len(stack) - 1 | |
return stack # optional | |
def display(stack): | |
return stack[::-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment