-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackUsingLinkedList.py
More file actions
61 lines (50 loc) · 1.06 KB
/
Copy pathStackUsingLinkedList.py
File metadata and controls
61 lines (50 loc) · 1.06 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Node:
def __init__(self,data):
self.data=data
self.next=None
class Stack:
def __init__(self):
self.head=None
def is_empty(self):
if self.head== None:
return True
return False
def push(self,data):
new_node=Node(data)
if self.head==None:
self.head=new_node
else:
new_node.next=self.head
self.head=new_node
def pop(self):
if self.head==None:
print("STACK UNDERFLOW")
else:
print(self.head.data)
self.head=self.head.next
def print(self):
current=self.head
while current:
print(current.data, end=" , ")
current=current.next
def main():
s=Stack()
print(s.is_empty())
s.push(1)
s.push(2)
s.push(3)
s.push(4)
s.push(5)
s.push(6)
s.push(7)
s.push(8)
s.push(9)
s.push(10)
s.print()
s.pop()
s.pop()
s.pop()
s.pop()
print("AFTER POP $ NUMBER'S FROM THE TOP")
s.print()
main()