二分查找
1 Position BinarySearch( List L, ElementType X ) 2 { 3 int left = 1, right = L->Last; 4 int mid; 5 while(left <= right) 6 { 7 mid = (left + right) / 2; 8 if(L->Data[mid] > X) //X在左侧 9 right = mid - 1; 10 else if(L->Data[mid] < X) //X在右侧 11 left = mid + 1; 12 else 13 return mid; //X==L->Data[mid] 14 } 15 return NotFound; //没找到 16 }