-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_Node_Single_List.py
More file actions
46 lines (40 loc) · 959 Bytes
/
delete_Node_Single_List.py
File metadata and controls
46 lines (40 loc) · 959 Bytes
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
class Node:
def __init__(self,data):
self.data=data
self.next=None
class LinkList:
def __init__(self):
self.head=None
def push(self,newdata):
new_node=Node(newdata)
new_node.next=self.head
self.head=new_node
def delete(self,target):
temp=self.head
if temp is None:
return
if temp is not None:
if temp.data==target:
self.head=temp.next
temp=None
return
while(temp is not None):
if temp.data == target:
break
prev=temp
temp=temp.next
prev.next=temp.next
temp=None
def printList(self):
temp=self.head
while temp:
print(temp.data)
temp=temp.next
test=LinkList()
test.push(4)
test.push(3)
test.push(2)
test.push(1)
print(test.printList())
test.delete(2)
print(test.printList())