-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcll.py
More file actions
60 lines (58 loc) · 1.57 KB
/
Copy pathcll.py
File metadata and controls
60 lines (58 loc) · 1.57 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
class node:
def __init__(self,data):
self.data=data
self.next=None
self.prev=None
class cll:
def __init__(self):
self.head=None
self.tail=None
def insertatbeg(self,data):
if self.head==None:
self.head=node(data)
self.tail=self.head
else:
new=node(data)
new.next=self.head
self.head.prev=new
self.head=new
self.tail.next=self.head
self.head.prev=self.tail
def insertatend(self,data):
if self.head==None:
self.head=node(data)
self.tail=self.head
else:
new=node(data)
self.tail.next=new
new.prev=self.tail
self.tail.next=self.head
self.head.prev=self.tail
def printing(self):
print(self.head.data)
i=self.head.next
while i!=self.head:
print(i.data)
i=i.next
'''def reverse(self):
prev=None
current=self.head
while current:
if current.next==None:
self.head=current
current.next,current.prev=current.prev,current.next
current=current.prev'''
'''def deleteatbeg(self):
self.head=self.head.next
self.head.prev=None'''
'''def deleteatend(self):
self.tail=self.tail.prev
self.tail.next=None'''
o=cll()
for i in range(1,6):
o.insertatbeg(i)
o.insertatend(i)
#o.deleteatbeg()
#o.deleteatend()
o.printing()
#o.reverse()