Hello,I was trying to know the position of Largest and smallest element in the array using sorting and binary search but i feel something wrong with my binary search implementation.I will be obliged please help me finding the error.link
Binary Search works only on sorted array and you are passing b which is unsorted array.
func bsearch: First Call(11) b = [33,44,11,22] key = 11 mid = 2 b[mid] = b = 11 return 2 Next call(44) b = [33,44,11,22] key = 44 mid = 2 b[mid] = b = 11 l = 3 mid = 3 b[mid] = b = 22 l = 4 return -1
Oh i am so sorry i sorted a and passed b as an argument thanks for your attention mister.
also you need to replace