1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void search(const int *tab, int length, int x)
{
  int tmp;
  int stop;
  int start;
  int result;
  int i;

  start = 0;
  stop = length;
  while (start != stop) {
    i = ((start + stop) / 2);
    tmp = tab[i];
    if (x == tmp) {
      start = i;
      break;
    } else {
    };
    if (x > tmp) {
      start = (i + 1);
      continue;
    } else {
    };
    if (x < tmp) {
      stop = i;
    } else {
    };
  };
  tmp = tab[start];
  if (tmp == x) {
    result = start;
  } else {
    result = (0 - 1);
  };

}