-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdll.py
More file actions
55 lines (53 loc) · 1.39 KB
/
dll.py
File metadata and controls
55 lines (53 loc) · 1.39 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
class node:
def __init__(self,data):
self.data=data
self.next=None
self.prev=None
class dll:
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'''
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
def printing(self):
i=self.head
while i:
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=dll()
for i in range(1,6):
#o.insertatbeg(i)
o.insertatend(i)
#o.deleteatbeg()
o.deleteatend()
o.printing()
#o.reverse()