Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyClassBinSearch
#python 3.6.9 #PyClassBinSearch: example of binary search using class in Python #this code is created by Rezaul Hoque on April 19,2022; #contact: jewelmrh@yahoo.com; Dhaka, Bangladesh,https://rezaulhoque.wordpress.com;https:hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; class Search: def __init__(self): self.thelist=[ ] def add(self,element): self.thelist.append(element) def binsearch(self,thelist,item,first,last): while first<=last: mid=(first+last)//2 if item<self.thelist[mid]: last=mid-1 elif item>self.thelist[mid]: first=mid+1 else: return mid return -1 def display(self): print(self.thelist) k=Search() c=Search() k.add(1) k.add(2) k.add(3) c.add('A') c.add('Z') c.add('Y') k.display() c.display() item=int(input("Enter item you look for:\n")) a=k.binsearch(k,item,0,2) if(a==-1): print("item is not found") else: print("item is found at",a) item2=(input("Enter character you look for:\n")) str=c.binsearch(c,item2,0,2) if(str==-1): print("item is not found") else: print("item is found at",str)
run
|
edit
|
history
|
help
0
variables.py
Faiha Lesson 4
Ns
My first experience on rextester !
Принцип наименьшего времени Ферма
list_copy_shallow_deep.py
Celcius to Fahrenheit
double
Юра и заселение
H.W5