Skip to content

Commit cc34ea1

Browse files
committed
feat: Add stack
1 parent a868b0a commit cc34ea1

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The project contains following problems:
4141
30. To implement breadth-first search.
4242
31. To implement depth-first search.
4343

44+
32. To implement a stack.
45+
4446
*IN production...
4547

4648
Note: Most of the above programs can be run directly from the command line.

stack.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Stack:
2+
def __init__(self):
3+
self.items = []
4+
5+
def push(self, item):
6+
return self.items.append(item)
7+
8+
def pop(self):
9+
return self.items.pop()
10+
11+
def is_empty(self):
12+
return self.items == []
13+
14+
def size(self):
15+
return len(self.items)
16+
17+
18+
s = Stack()
19+
s.push(54)
20+
s.push(45)
21+
s.push('+')
22+
print(s.size())
23+
print(s.pop())
24+
s.push(True)
25+
26+
while not s.is_empty():
27+
print(s.pop(), end=' ')

0 commit comments

Comments
 (0)