算法导论
文章平均质量分 77
红桃KK
这个作者很懒,什么都没留下…
展开
-
插入排序与归并排序
#include using namespace std;void insertSort(int a[],int n){ for(int j = 1; j < n ;j++){ int key = a[j]; int i = j - 1; while(i >= 0 && a[i] > key){ a[i + 1] = a[i]; i--; } a[i + 1原创 2013-04-23 21:16:46 · 562 阅读 · 0 评论 -
递归的一些例子
一、由整数1,2,3.....组成了一颗无限大的满二叉树,给出2个正整数,代表二叉树中的节点,求出这2个节点最近的公共祖先int common(int x , int y){ if(x = y) return x; else if(x > y) return common(x/2,y); else return common(x,y/2);}二、求逆波兰表达式原创 2013-04-29 21:33:12 · 904 阅读 · 0 评论 -
快速排序
#include using namespace std;void swap(int &a,int &b){ int temp; temp = a; a = b; b = temp;}int partition(int A[],int p ,int r){ int x = A[r]; int i = p - 1; for(int原创 2013-05-03 00:46:27 · 651 阅读 · 0 评论 -
堆排序
#include#include #include #include using namespace std;void swap(int &a,int &b){ a = a ^ b; b = a ^ b; a = a ^ b;}void max_heap(int *a,int i,int size){ int l = 2 * i; int r = 2 * i +原创 2013-06-02 21:45:21 · 572 阅读 · 0 评论 -
最小生成树
#define MAXN 101int n, ret;int map[MAXN][MAXN];void prim(){ int closet[MAXN]; int dist[MAXN]; int i, j; for ( i=0; i<n; i++) { closet[i] = 0; dist[i] = map[0][i]; } closet[0] = 1; in原创 2013-06-06 14:09:56 · 592 阅读 · 0 评论 -
快速乘方
#include#include #include #include using namespace std;int main(){ int a,b,k; while(cin >> a >> b >> k) { int temp = a,ans = 1; while(k){ if(k % 2 == 1)原创 2013-06-01 14:32:25 · 805 阅读 · 0 评论