Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,9 @@ | |||
��¼һЩͨ�õĺ������������ | 记录一些通用的函数,方便查找 | ||
|
|||
|
|||
minPrintf.cpp | |||
记录了变长参数的知识点 | |||
|
|||
|
|||
binarySearch.cpp | |||
二分查找 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
|
|||
|
|||
int binarySearch(int value, int array[], int arraySize) | |||
{ | |||
int low = 0; | |||
int high = arraySize - 1; | |||
int mid = 0; | |||
|
|||
while(low <= high) | |||
{ | |||
mid = (low + high) / 2; | |||
if(value < array[mid]) | |||
{ | |||
high = mid - 1; | |||
} | |||
else if(value > array[mid]) | |||
{ | |||
low = mid + 1; | |||
} | |||
else | |||
{ | |||
return mid; | |||
} | |||
} | |||
|
|||
return -1; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters