/**
Find (Array)
1> Sequential Lookup: It is the traversal of an array, each element is compared to that element, but the problem is less efficient
2> Binary Lookup: The condition is that the array must be sequential
*/
#include <stdio.h>
#define N 2
int main ()
{
Binary find
/*
Idea: the element is compared with the intermediate element, if there is, otherwise, determine the element in which part, continue to find;
*/
Any input integer x to find an element with the same x value in an ordered array
Defining input data
int x =-1;
Arrays Array
int array[10] = {2, 10, 19, 22, 34, 36, 55, 67, 76, 88};
scanf ("%d", &x);
Define start element subscript start, tail end, middle element subscript mid
int start = 0;
int end = 9;
int mid = (start + end)/2;
while (Array[mid]! = x && (end > Start)) {
if (x < Array[mid]) {
end = Mid-1;
}else{
Start = mid + 1;
}
Mid = (start + end)/2;
}
printf ("%d\n", mid);
return 0;
}
C Language Search algorithm