Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINEAR SEARCH ON A SINGLY LINKED LIST #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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)