linear search in c++ code example
Example 1: linear search python
def linear_search(a, key):
position = 0
flag = False
while position < len(a) and not flag:
if a[position] == key:
flag = True
else:
position = position + 1
return flag
Example 2: linear search in c++
bool linearsearch(int A[], int N, int X) {
for (int i=0; i<N; i++)
if (A[i] == X) return true;
return false;
}