1、冒泡排序 void test1(int arr[],int len){
for(int i=0;i<len-1;i++){
for(int j=0;j<len-1-i;j++){
if(arr[j]>arr[j+1]){
int temp =arr[j]; arr[j] =arr[j+1]; arr[j+1] =temp; } }
}
}
2、选择排序
void test2(int arr[],int len){
for(int i=0;i<len-1;i++){
for(int j=i+1;j<len;j++){
if(arr>arr[j]){
int temp =arr; arr = arr[j]; arr[j] = temp;
}
} }
}
3、折半查找 int search(int arr[],int len,int key){
int low=0,high=len-1,mid;
while(low<=high){
mid = (low+high)/2;
if(key>arr[mid]){
low =mid+1;
}else if(key<arr[mid]){
high =mid-1
}else{
return mid;
}
}
return -1;
}
大家看看,折半不知道对不,大家帮我检查一下,谢谢啦!
|