Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions data-structures/Stack/StackImplementation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

from sys import maxsize

def createStack():
stack = []
return stack

def isEmpty(stack):
return len(stack) == 0

def push(stack, item):
stack.append(item)
print(item + " pushed to stack ")

# Function to remove an item from stack. It decreases size by 1
def pop(stack):
if (isEmpty(stack)):
return str(-maxsize -1) # return minus infinite

return stack.pop()

# Function to return the top from stack without removing it
def peek(stack):
if (isEmpty(stack)):
return str(-maxsize -1) # return minus infinite
return stack[len(stack) - 1]

stack = createStack()
push(stack, str(10))
push(stack, str(20))
push(stack, str(30))
print(pop(stack) + " popped from stack")