Skip to content

Commit

Permalink
Create 01-复杂度3 二分查找 (20 分).c
Browse files Browse the repository at this point in the history
  • Loading branch information
hao14293 authored May 1, 2019
1 parent 8883d67 commit 44382c7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ZJU_MOOC_数据结构/01-复杂度3 二分查找 (20 分).c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Position BinarySearch( List L, ElementType X ){
int p = 0;
int s = 1;
int e = L->Last;
int num = e/2;
while(num--){
int mid = (s + e) / 2;
if(L->Data[mid] == X){
p = mid;
break;
}else if(L->Data[mid] > X){
e = mid - 1;
}else if(L->Data[mid] < X){
s = mid + 1;
}

}
if(p == 0)
return NotFound;
return p;
}

0 comments on commit 44382c7

Please sign in to comment.