12 2012 档案

摘要:将数组进行循环左移位的代码实现,杂技算法,确实很杂技:#include <stdio.h>#include <stdlib.h>#define swap(a,b) {int temp = (a); (a) = (b); (b) = temp;}void rotate(int a[], int n, int m){ int i, len, p = 0, r = n - 1; while(1) { len = 1 + r - p; if(2 * m == len) { for(i = 0; i < m; ++i) { swap(a[p + i], a[p + m + 阅读全文
posted @ 2012-12-18 03:16 knull 阅读(255) 评论(0) 推荐(0)
摘要:#ifndef BINARY_TREE#define BINARY_TREE#include <iostream>#include <stdio.h>#include <stack>using namespace std;class binaryTree{private: struct btNode { char data; btNode *left, *right; btNode(char c):data(c){} }; btNode *root; int size; //非递归后序遍历辅助数据的类型定义 s... 阅读全文
posted @ 2012-12-14 19:50 knull 阅读(196) 评论(0) 推荐(0)
摘要:测试用例为两千万的int数组,使用随机数生成器生成整个数组的数值,测试结果为:堆排序14.8秒;qsort库函数6.4秒;归并排序4.4秒;快速排序版本1为2.7秒;快速排序版本2为2.7秒;二进制快速排序为4.8秒;基数排序为0.95秒,大比分领先于其他常见排序算法。附:测试代码如下(gcc -O3 test.c -o test.exe)#include <stdio.h>#include <stdlib.h>#include <time.h>#include <limits.h>#include <string.h>#includ 阅读全文
posted @ 2012-12-11 21:45 knull 阅读(617) 评论(0) 推荐(0)