2012年4月29日
摘要: #include <iostream>#include <cstdlib>#include<cstring>using namespace std;#define LQ( a, b) ((a) <= (b))#define EQ(a, b) ((a) == (b))#define LT(a, b) ((a) < (b))void Merge(int a[], int *d, int i, int m, int n){ //将有序的a[i...m],有序的a[m+1...n]归并为有序的d[i...n]; int j, k, l; for(j = 阅读全文
posted @ 2012-04-29 15:53 tomctx 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 对已排列好的非递减数组进行查找。(1)非递归算法:#include <iostream>#include<cstdlib>using namespace std;template <typename Type>int binarySearch(Type a[], const Type &x, int n){ int low = 0; int high = n - 1; int middle; while(low <= high){ middle = (low + high) / 2; if(x == a[middle]) return mid. 阅读全文
posted @ 2012-04-29 13:29 tomctx 阅读(191) 评论(0) 推荐(0) 编辑