typedefint ElementType; typedefint Position ; typedefstructLNode *List;
structLNode { ElementType Data[MAXSIZE]; Position Last; };
List CreatList(); Position BinarySearch(List ,ElementType X);
List CreatList() { List L; L = (List)malloc(sizeof(struct LNode)); L->Last = -1; return L; } Position BinarySearch(List L,ElementType X) { int left = 1; int right = L->Last; while(left < right) { int center = (left+right) / 2; if(X > L->Data[center]) { left = center + 1; }elseif(X < L->Data[center]) { right = center - 1; }else{ return center; } } return NotFound; } intmain() { List L; ElementType X; Position P;
L = CreatList(); for(int i = 1;i < 4;++ i) { L->Data[i] = 2 * i - 1; } L->Last = 3; scanf("%d",&X); P = BinarySearch(L,X); printf("%d\n",P);