This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def LinearSearch(arr,x,n): | |
for i in range(n): | |
if arr[i]==x: | |
return i; | |
return -1; | |
arr=[5,3,9,34,56,77]; | |
x=56; | |
n=len(arr); | |
obj=LinearSearch(arr,x,n); | |
if obj==-1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pos=-1; | |
def binary_search(arr,n): | |
l=0; | |
r=len(arr); | |
while l<=r: | |
mid=(l+r)//2; | |
if arr[mid]==n: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class node(): | |
def __init__(self,data=None): | |
self.data=data; | |
self.next=None; | |
class SinglyLinklist(): | |
def __init__(self): | |
self.head=None; | |
def display(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertnode(self,newnode): | |
Newnode=node(newnode); | |
Newnode.next=self.head; | |
self.head=Newnode; | |
obj.insertnode(int(input('enter the item=='))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def middleinsert(self,mid,newnode): | |
Newnode=node(newnode); | |
Newnode.next=mid.next; | |
mid.next=Newnode | |
obj.middleinsert(obj.head.next,int(input('enter the item in middle in list=='))); | |
obj.display() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def endinsert(self,newnode): | |
Newnode=node(newnode); | |
if self.head is None: | |
self.head=Newnode; | |
return True; | |
last=self.head; | |
while last.next is not None: | |
last=last.next; | |
last.next=Newnode; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete(self,remove): | |
Head=self.head; | |
if Head is not None: | |
if Head.data==remove: | |
self.head=Head.next; | |
Head=None; | |
return True; | |
while Head is not None: | |
if Head.data==remove: | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class node(): | |
def __init__(self,data=None): | |
self.data=data; | |
self.next=None; | |
class SinglyLinklist(): | |
def __init__(self): | |
self.head=None; | |
def Insert(self,newnode): |
OlderNewer