Check out example codes for "linear search in c++". It will help you in understanding the concepts better.

Code Example 1

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

Code Example 2

let arr = [1, 3, 5, 7, 8, 9];
let binarySearch = (arr, x , strt, end) => {
  if(end < strt) return false;
  let mid = Math.floor((strt + end) / 2);
  if(arr[mid] === x) {
    return true;
  }
  if(arr[mid] < x) {
    return binarySearch(arr, x, mid+1, end);
  }
  if(arr[mid] > x) {
    return binarySearch(arr, x , strt, mid-1);
  }
}

let strt = 0, end = arr.length -1;
let bool = binarySearch(arr, 7, strt, end);
console.log(bool);

Code Example 3

bool linearsearch(int A[], int N, int X) {
  for (int i=0; i<N; i++) 
    if (A[i] == X) return true;
  return false;
}

Learn ReactJs, React Native from akashmittal.com