上一页 1 2 3 4 5 6 7 8 ··· 10 下一页
摘要: #include <stdio.h>//not find will return -1//find will return the indexint searchR(int a[], int l, int r, int key){ if(l>r) return -1; int m=(l+r)/2; if(a[m] == key) return m; if(l==r) return -1; if(key < a[m]) return searchR(a, l, m-1, key); else return searchR(a, m+... 阅读全文
posted @ 2012-11-13 10:21 wouldguan 阅读(165) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}void fixdown(int a[], int k, int N){ while(2*k <= N) { int j=k*2; if(j<N && a[j]<a[j+1]) j++; if(!(a[k]<a[j])) break; exch(a[k], a[j]); k = j; }}void heapsort(int a[], int l... 阅读全文
posted @ 2012-11-12 12:34 wouldguan 阅读(710) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}void fixup(int a[], int k){ while(k>1 && a[k/2]<a[k]) { exch(a[k/2], a[k]); k/=2; }}void fixdown(int a[], int k, int N){ while(2*k <= N) { int j=k*2; if(j<N && a[j]<a[j+1]) j... 阅读全文
posted @ 2012-11-12 10:49 wouldguan 阅读(202) 评论(0) 推荐(0) 编辑
摘要: void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}void fixup(int a[], int k){ while(k>1 && a[k/2]<a[k]) { exch(a[k/2], a[k]); k/=2; }}void fixdown(int a[], int k, int N){ while(2*k <= N) { int j=k*2; if(k<N && a[j]<a[j+1]) j++; if(!(a[... 阅读全文
posted @ 2012-11-12 09:50 wouldguan 阅读(192) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stack>using namespace std;void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}int partition(int a[], int l, int r){ int i=l-1; int j=r; int val = a[r]; while(1) { while(val > a[++i]); while(val < a[--j]) if(j == l) brea... 阅读全文
posted @ 2012-11-11 21:13 wouldguan 阅读(641) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stack>using namespace std;void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}int partition(int a[], int l, int r){ int i=l-1; int j=r; int val = a[r]; while(1) { while(val > a[++i]); while(val < a[--j]) if(j == l) brea... 阅读全文
posted @ 2012-11-11 20:37 wouldguan 阅读(301) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>void exch(int& a, int &b){ int tmp = a; a = b; b = tmp;}int partition(int a[], int l, int r){ int i=l-1; int j=r; int val = a[r]; while(1) { while(val > a[++i]); while(val < a[--j]) if(j == l) break; if(i >= j) break; e... 阅读全文
posted @ 2012-11-11 20:08 wouldguan 阅读(298) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <time.h>void shellsort(int a[], int l, int r){ int h; //step 1 4 13 40 121 ... for(h=1; h<=(r-l)/9; h=h*3+1); for(; h>0; h=h/3) { for(int i=l+h; i<=r; i++) { int j=i; int v = a[i]; while(j>=l+h && v<a[j-h]) ... 阅读全文
posted @ 2012-11-11 14:39 wouldguan 阅读(650) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>int max(const int a[], int l, int r){ if(l == r) return a[l]; int mid = (l+r) / 2; int u = max(a, l, mid); int v = max(a, mid+1, r); return u>v? u : v;}int main(){ int a[5] = {4,2,6,4,8}; printf("%d", max(a, 0, 4)); return 0;} 阅读全文
posted @ 2012-11-11 11:44 wouldguan 阅读(145) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>int main(){ printf("file:%s\n", __FILE__); printf("date:%s\n", __DATE__); printf("time:%s\n", __TIME__); printf("line:%d\n", __LINE__); printf("function:%s\n", __FUNCTION__); printf("func:%s\n", __func__); return 0;} 阅读全文
posted @ 2012-11-04 23:01 wouldguan 阅读(111) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 ··· 10 下一页