-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLL.PY
More file actions
132 lines (118 loc) · 2.82 KB
/
CLL.PY
File metadata and controls
132 lines (118 loc) · 2.82 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class createnode:
def __init__(self,data):
self.data=data
self.next=None
class Unordered_list:
def __init__(self):
self.head=None
self.last=None
#######INsertion at the last###
def createlist(self,data):
node=createnode(data)
if self.head==None:
self.head=node
self.head.next=self.head
self.last=self.head.next
else:
node.next=self.last.next
self.last.next=node
self.last=node
#######Insetion at the begiing##
def insertatbegin(self,data):
node=createnode(data)
if self.head==None:
self.head=node
self.head.next=self.head
self.last=self.head.next
else:
node.next=self.last.next
self.last.next=node
head=self.last
########Insertion after a postion#####
def insertatpos(self,data,srchd_data):
node=createnode(data)
temp=self.last.next
while(temp!=self.last):
if(temp.data==srchd_data):
node.next=temp.next
temp.next=node
break
else: temp=temp.next
########Insetion before a position####
def insertbfrpos(self,data,srchd_data):
node=createnode(data)
temp=self.last.next
while(temp.data!=srchd_data):
prev=temp
temp=temp.next
node.next=prev.next
prev.next=node
#########deleting the head of a node####
def delhead(self):
temp=self.head
self.last.next=temp.next
self.head=self.last.next
######Deleting the last node#####
def dellast(self):
temp=self.head
while(temp!=self.last):
prev=temp
temp=temp.next
prev.next=temp.next
self.head=prev.next
#######Deleting any of the node part2
def delany(self,srchd_data):
temp=self.head
while(temp.data!=srchd_data):
prev=temp
temp=temp.next
Next_to_temp=temp.next
prev.next=Next_to_temp
self.head=Next_to_temp
#######Reversing a lint list#####
def reverselist(self):
temp_last=self.last
self.head.next=temp_last
temp=self.head
while(temp!=self.last):
prev=temp
next_temp=temp.next
next_temp.next=prev
temp=temp.next
self.head=self.last
self.head.next=self.last
######printing the list######
def printlist(self):
temp=self.last.next
while True:
print(temp.data)
temp=temp.next
if temp==self.last.next:
break;
a=Unordered_list()
a.createlist(10)
a.createlist(20)
a.createlist(30)
a.createlist(45)
a.printlist()
print("Now insert data at begining")
a.insertatbegin(60)
a.printlist()
print("insertion at some position")
a.insertatpos(70,30)
a.printlist()
print("insertion before some position")
a.insertbfrpos(80,30)
a.printlist()
print("Deletion of head")
a.delhead()
a.printlist()
print("deleting the last node ")
a.dellast()
a.printlist()
print("deleting any of the node")
a.delany(20)
a.printlist()
print("printing the list")
a.reverselist()
a.printlist()