We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a868b0a commit cc34ea1Copy full SHA for cc34ea1
2 files changed
README.md
@@ -41,6 +41,8 @@ The project contains following problems:
41
30. To implement breadth-first search.
42
31. To implement depth-first search.
43
44
+32. To implement a stack.
45
+
46
*IN production...
47
48
Note: Most of the above programs can be run directly from the command line.
stack.py
@@ -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