From 43cc8ffddd632ba07ef91ac4d4daeede949341c6 Mon Sep 17 00:00:00 2001 From: Divyamop <76569185+Divyamop@users.noreply.github.com> Date: Sat, 16 Oct 2021 19:05:47 +0530 Subject: [PATCH] LINEAR SEARCH ON A SINGLY LINKED LIST --- DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY diff --git a/DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY b/DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY new file mode 100644 index 0000000..21eacdc --- /dev/null +++ b/DSA/LINEARSEARCHONASINGLYLINKEDLIST.PY @@ -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) \ No newline at end of file