Skip to content

Instantly share code, notes, and snippets.

View mahendrarathore1742's full-sized avatar
:octocat:

Mahendra Singh Rathore mahendrarathore1742

:octocat:
  • india
  • 09:37 (UTC +05:30)
View GitHub Profile
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:
@mahendrarathore1742
mahendrarathore1742 / python
Last active November 7, 2019 04:03
Binary Search in python
pos=-1;
def binary_search(arr,n):
l=0;
r=len(arr);
while l<=r:
mid=(l+r)//2;
if arr[mid]==n:
@mahendrarathore1742
mahendrarathore1742 / singly Linklist
Created October 28, 2019 10:12
singly Linklist
def insertnode(self,newnode):
Newnode=node(newnode);
Newnode.next=self.head;
self.head=Newnode;
obj.insertnode(int(input('enter the item==')));
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()
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;
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;
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):