-
Notifications
You must be signed in to change notification settings - Fork 331
/
ROTATEDOUBLYLINKEDLIST.PY
54 lines (49 loc) · 1.38 KB
/
ROTATEDOUBLYLINKEDLIST.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Node:
def __init__(self,data):
self.data = data
self.previous = None
self.next = None
class DLL:
def __init__(self):
self.head=None
self.tail=None
self.size=0
def addNode(self,data):
new=Node(data)
if self.head==None:
self.head=new
self.tail=new
self.head.previous=None
self.tail.next=None
else:
self.tail.next=new
new.previous=self.tail
self.tail=new
self.tail.next=None
self.size+=1
def printll(self):
curr=self.head
while curr is not None:
print(curr.data,end =" ")
curr = curr.next
def rll(self,n):
if n==0 or n>=self.size:
return
if self.head==None:
return
curr=self.head
for i in range(1,n):
curr=curr.next
self.tail.next=self.head
self.head=curr.next
self.head.previous=None
self.tail=curr
self.tail.next=None
a=DLL()
print("ENTER THE ELEMENTS TO BE ADDED IN THE DOUBLY LINKED LIST : ")
l=[int(x) for x in input().split(" ")]
for i in l:
a.addNode(i)
n=int(input("ENTER HOW MUCH YOU WANT TO ROTATE THE DOUBLY LINKED LIST : "))
a.rll(n)
a.printll()