mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-24 09:21:24 -04:00
add link to the new revision of my book, organize the folders to add further examples
This commit is contained in:
parent
6d78f5e3fd
commit
aa5010594e
140 changed files with 13 additions and 15 deletions
40
src/examples_book/adt/stacks/stack.py
Normal file
40
src/examples_book/adt/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