-
Notifications
You must be signed in to change notification settings - Fork 179
/
Linked_List.py
38 lines (36 loc) · 968 Bytes
/
Linked_List.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
37
38
class Node:
def __init__(self):
self.data=None
self.next=None
class Linked_List(Node):
def __init__(self):
self.start=None
def Create(self):
while True:
newnode=Node()
newnode.data=int(input("Enter data part : "))
if self.start==None:
self.start=newnode
current=newnode
else:
current.next=newnode
current=newnode
char=input("DO YOU WANT TO ENTER MORE NODES? : ")
if char in ('n','N'):
break
def Display(self):
ptr=self.start
print("\n\nDATA IS AS FOLLOWS : \n")
while ptr!=None:
print(ptr.data,end=' ')
ptr=ptr.next
print()
def Reverse(self,ptr):
if ptr==None:
return
self.Reverse(ptr.next)
print(ptr.data)
l1=Linked_List()
l1.Create()
l1.Display()
l1.Reverse(l1.start)