forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
31 lines (27 loc) · 751 Bytes
/
Stack.py
File metadata and controls
31 lines (27 loc) · 751 Bytes
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
class Node:
def __init__(self,data=None,next=None):
self.data=data
self.next=next
class Stack:
def __init__(self):
self.head=None
def insert(self,data):
Newnode=Node(data)
if(self.head):
current=self.head
self.head=Newnode
self.head.next=current
else:
self.head=Newnode
def printstack(self):
current=self.head
while(current):
print(current.data)
current=current.next
no_of_nodes=int(input("Enter no of nodes::"))
St=Stack()
while(no_of_nodes):
value=int(input("Enter value to stack::"))
St.insert(value)
no_of_nodes=no_of_nodes-1
St.printstack()