MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / BinarySearch

Method BinarySearch

Arrays/18_Menu_Based_problem.cpp:113–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111 return -1;
112}
113int Array::BinarySearch(int key)
114{
115 int l,mid,h;
116 l=0;
117 h=length-1;
118
119 while(l<=h)
120 {
121 mid=(l+h)/2;
122 if(key==A[mid])
123 return mid;
124 else if(key<A[mid])
125 h=mid-1;
126 else
127 l=mid+1;
128 }
129 return -1;
130}
131int Array::Get(int index)
132{
133 if(index>=0 && index<length)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected