mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-24 01:11:35 -04:00
organized
This commit is contained in:
parent
77731415d1
commit
5ed530430c
60 changed files with 439 additions and 563 deletions
40
src/abstract_structures/stacks/stack.py
Normal file
40
src/abstract_structures/stacks/stack.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/python3
|
||||
# mari von steinkirch @2013
|
||||
# steinkirch at gmail
|
||||
|
||||
class Stack(object):
|
||||
''' define the stack class '''
|
||||
def __init__(self):
|
||||
self.items = []
|
||||
|
||||
def isEmpty(self):
|
||||
return self.items == []
|
||||
|
||||
def push(self, items):
|
||||
self.items.append(items)
|
||||
|
||||
def pop(self):
|
||||
return self.items.pop()
|
||||
|
||||
def peek(self):
|
||||
return self.items[-1]
|
||||
|
||||
def size(self):
|
||||
return len(self.items)
|
||||
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
stack = Stack()
|
||||
stack.push(1)
|
||||
stack.push(2)
|
||||
stack.push(3)
|
||||
print(stack.size())
|
||||
print(stack.peek())
|
||||
print(stack.pop())
|
||||
print(stack.peek())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue