-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.py
36 lines (31 loc) · 793 Bytes
/
stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Node:
def __init__(self, value):
self.value = value
self.next = None
class Stack:
def __init__(self):
self.head = None
def push(self, node):
node.next = self.head
self.head = node
def pop(self):
if (self.head is not None):
self.head = self.head.next
def printStack(self):
node = self.head
while (node is not None):
print(node.value)
node = node.next
if __name__ == "__main__":
stack1 = Stack()
stack1.push(Node(1))
stack1.push(Node(23))
stack1.push(Node(42))
stack1.printStack()
stack1.pop()
print("------------------")
stack1.printStack()
stack1.pop()
stack1.pop()
print("------------------")
stack1.printStack()