上一页 1 2 3 4 5 6 7 8 9 10 ··· 28 下一页
摘要: 快速排序的思路是:首先拿a[start]作为轴,将原数组中比a[start]小的放small数组,将原数组中比a[start]大的放big数组,最后在将small数组 和a[start]值和big数组中的数复制回原数组。以此递归,使数组逐渐有序。快速排序的平均时间复杂度是nlogn。#include#include#define N 1000000int array[N];int small[N];int big[N];void init_array(int a[],int n);void print_array(int a[],int n);void quick_sort(int a[],i 阅读全文
posted @ 2013-12-31 14:00 博园少主 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 折半查找的前提是有序的,与中间值进行比较,如果有序的则返回;否则,改变始末位置,再进行查找实现方法:1 循环实现 2 递归实现1 循环实现#includeint binary_search(int *array,int n,int data);int main(){ int array[10]={ 1,2,3,4,5,6,7,8,9,10 }; printf("please input the number that you want search\n"); int num; scanf("%d",&num); int result=binary 阅读全文
posted @ 2013-12-31 13:56 博园少主 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1,复杂度:O (n log n)2路归并排序的基本思想:n个记录,看作n个有序子序列,每个子序列的长度为1,然后两两归并,得到n/2(向上取整)个长度为2或者1的有序子序列;再两两归并,......,如此重复,知道得到一个长度为n的有序序列位置。#include #include #include #include void merge(int array[], int low, int mid, int high){ int i, k; int *temp = (int *) malloc((high-low+1) * sizeof(int)); //申请空间,... 阅读全文
posted @ 2013-12-31 13:53 博园少主 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 1 http://www.cnblogs.com/zabery/archive/2011/07/26/2117103.html2 http://www.cnblogs.com/luchen927/archive/2012/03/08/2381446.html3 http://www.cnblogs.com/chenbin7/archive/2011/10/02/2197933.html 阅读全文
posted @ 2013-12-31 13:51 博园少主 阅读(98) 评论(0) 推荐(0) 编辑
摘要: #include /*头文件*/#define M 100 /*定义常量*/int R[M]; /*定义数组*/int main(){ int i,j,temp,n; printf("input n size:");/*数组大小*/ scanf("%d",&n); printf("input number one by one:\n"); for(i=1;iR[j+1]) /*判断前一个数据元素是否比后一个大,大于则交换*/ { temp=R[j]; ... 阅读全文
posted @ 2013-12-31 13:22 博园少主 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 一.直接插入排序(Straight Insertion Sort) 排序的过程如下:给定无需序列:(3,6,9,7,1,8,2,4) ① 3,6,9,7,1,8,2,4 (将6插入到有序序列3中) ② 3,6,9,7,1,8,2,4 (将9插入到有序序列3,6中) ③ 3,6,9,7,1,8,2,4 (将7插入到有序序列3,6,9中) ④ 3,6,7,9,1,8,2,4 (将1插入到有序序列3,6,7,9中) ⑤ 1,3,6,7,9,8,2,4 (将8插入到有序序列1,3,6,7,9中) ⑥ 1,3,6,7,8,9,2,4 (将2插入到有序序列1,3,6,7,8,9中) ⑦ 1,2,3,6,7 阅读全文
posted @ 2013-12-31 13:15 博园少主 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 转载 http://www.cnblogs.com/Leo_wl/p/3382120.html让我有点以外的是在数据量达到1W~10W之间,希尔排序竟然比快速排序效率还要高。贴上完整代码!一,冒泡排序 冒泡排序的时间复杂度为O(n²),在数据比较小的情况下各个算法效率差不多。 //冒泡排序//////////////////////////////////////////////////////////////////////////void BubleSort(int a[],int n){ int temp; bool flag=false; for (int i=0;i... 阅读全文
posted @ 2013-12-31 13:09 博园少主 阅读(288) 评论(0) 推荐(0) 编辑
摘要: //C++ 排序方法的总结#include #include using namespace std;/*采用插入法进行排序*/void InsertArray(int a[],int n, int* &b){int temp;int j;for(int i = 0;ia[j+1]) //后者小于前者,交换{temp = a[j];a[j] = a[j+1];a[j+1] = temp;if(j>0){j--;}}}b = a;}/*采用冒泡排序*/void SortArray(int a[], int n){int temp ;for (int i = 1;ia[j+1]){t 阅读全文
posted @ 2013-12-31 12:42 博园少主 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 下面贴几个简易的代码吧直接插入排序#include#includeint main(){ int i,j,n; int a[1000]; while(scanf("%d",&n)!=EOF) { for(i=1;i#includeint dlta[4]={8,4,2,1};int n;void shellsort(int a[],int dk){ int i,j; for(i=dk+1;i0&&a[0]#includeint n;int partition(int a[],int low,int high){ int pivotkey; a[0]=a 阅读全文
posted @ 2013-12-31 12:38 博园少主 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 排序算法常用的有:当数据量不大时 选择插入或者选择排序,不用冒泡排序;其次,当数据量大而又注重空间复杂性时选择快速排序或堆排序;再次,当数据量大而又允许使用较多附加空间时选择桶排序,最后,当要在已排序数据上增加若干新数据时选择插入排序.------- 摘自.C++数据结构原理与经典问题1、插入排序(直接插入排序、折半插入排序、希尔排序);2、交换排序(起泡排序、快速排序);3、选择排序(直接选择排序、堆排序);4、归并排序; 5、基数排序;排序方法的分类 1.按是否涉及数据的内、外存交换分 在排序过程中,若整个文件都是放在内存中处理,排序时不涉及数据的内、外存交换,则称之为内部排序(简称... 阅读全文
posted @ 2013-12-31 12:34 博园少主 阅读(187) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 28 下一页