/**
顺序表查找
*/int Sequential_Search(int *a, int n, int key)
{
int i ;
for (i = 0; i < n; i++) {
if(a[i] == key)
return i;
}
return -1;
}
/**
顺序表查找改进
*/int Sequential_Search(int *a, int n, int key)
{
int i = n-1;
if(a[0] == key)
return0;
a[0] = key;
while (a[i] != key) {
i--;
}
if(i == 0)
return -1;
return i;
}
有序表查找
/**
* 折半查找
*/int Binary_Search(int *a,int n, int key)
{
int low,high,mid;
low = 1;
high = n-1;
while (low <= high) {
mid = (low + high) / 2;
if(key < a[mid])
high = mid - 1;
elseif (key > a[mid])
low = mid + 1;
elsereturn mid;
}
return -1;
}
顺序表查找/** 顺序表查找 */int Sequential_Search(int *a, int n, int key){ int i ; for (i = 0; i < n; i++) { if(a[i] == key) return i; } return -1;}/** 顺序表查找改进 */int Se