Skip to content

Instantly share code, notes, and snippets.

@eitozx
Created June 10, 2022 13:57
Show Gist options
  • Save eitozx/65f4112b54f1b27f92d3f6ea3eb73072 to your computer and use it in GitHub Desktop.
Save eitozx/65f4112b54f1b27f92d3f6ea3eb73072 to your computer and use it in GitHub Desktop.
Push, Pop & Display Operations for Stack
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