Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Node:
def __init__(self,data):
self.data=data
self.next=None
def takeinput():
l=[int(x) for x in input().split(' ')]
head=None
tail=None
for i in l:
if i==-1:
break
new=Node(i)
if head is None:
head=new
tail=new
else:
tail.next=new
tail=new
return head
def ls(head,d):
if head is None:
return -1
i=0
while head is not None:
if head.data==d:
return i
i+=1
head=head.next
return -1
def printll(head):
while head is not None :
print(head.data, end = " ")
head = head.next
head=takeinput()
i=int(input())
ls(head,i)