Skip to content
This repository has been archived by the owner on Oct 7, 2019. It is now read-only.

Added stack implementation for Python3 #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
29 changes: 29 additions & 0 deletions data_structures/stacks/Python3/stack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3

class Stack:
def __init__(self):
self.items = []

def push(self, item):
self.items.append(item)

def pop(self):
return self.items.pop()

def peek(self):
return self.items[-1]

def size(self):
return len(self.items)

if __name__ == "__main__":
stack = Stack()
stack.push(1)
stack.push(2)

print("Size of stack: %d " % stack.size())
print("Stack.peek: %d" % stack.peek())


print("Stack.pop: %d" % stack.pop())
print("Stack.pop: %d" % stack.pop())