source: Deliverables/D4.1/DemoFinal/Search.c @ 1297

Last change on this file since 1297 was 671, checked in by mulligan, 10 years ago

Finished demo script for tomorrow.

File size: 469 bytes
Line 
1// #include<stdio.h>
2
3#define SIZE 5
4
5char search (char tab[], char size, char to_find) {
6  char low = 0, high = size-1, i;
7
8  while (high >= low) {
9    i = (high+low) / 2;
10    if (tab[i] == to_find) return i;
11    if (tab[i] > to_find) high = i-1;
12    if (tab[i] < to_find) low = i+1;
13  }
14
15  return (-1);
16}
17
18int main () {
19  char tab[SIZE] = {0, 18, 23, 57, 120};
20  char to_find = 26;
21  char res = search(tab, SIZE, to_find);
22
23  //  printf("%d\n", res);
24  return res;
25}
Note: See TracBrowser for help on using the repository browser.