-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistnode.py
More file actions
26 lines (25 loc) · 808 Bytes
/
listnode.py
File metadata and controls
26 lines (25 loc) · 808 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
class listnode:
def __init__(self,data):
self.data=data
self.next=None
def traversal(self,head):
node=head
while node is not None:
print(node.data)
node=node.next
def searchnode(self,head,target):
node=head
while node.next is not None and node.data !=target:
node=node.next
return node is not None
def removenode(self,head,target):
curnode=head
prednode=None
while curnode is not None and curnode.data !=target:
prednode=curnode
curnode=curnode.next
if curnode is not None:
if curnode is head:
head=curnode.next
else:
prednode.next=curnode.next