
C++ 排序
lanzhihui_
!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
排序--选择法
//选择排序#includeusing namespace std;void selectsort(int a[],int n){ int temp; for(int i=0;i<n;i++) { for(int j=i+1;j<n+1;j++) { if(a[i]>a[j])//第一位与其他所有数比较,比第一位大则交换,永远使第一位最小原创 2014-07-27 23:04:03 · 685 阅读 · 0 评论 -
C++标准库---sort()&stable_sort
sort(beg,end)sort(beg,end,op)stable(beg,end,)stable(beg,end,op)1.sort()与stable_sort()的上述第一形式,使用operator2.sort()与stable_sort()的上述第二形式,使用二元判断式op(elem1,elem2)作为排序准则,对区间[beg,end)内的所有元素进行原创 2014-12-22 20:29:24 · 1362 阅读 · 0 评论 -
C++标准库---partial_sort()&partial_sort_copy()
局部排序:partial_sort(beg,sortEnd,end)partial_sort(beg,sortEnd,end,op)1.以上第一种形式,以operator2.以上第二中形式,运用二元判断式:op(elem1,elem2)对区间[beg,end)内的元素进行排序,使区间[beg,sortEnd)内的元素处于有序状态。3.和sort(原创 2014-12-22 21:37:08 · 1433 阅读 · 0 评论 -
堆排序
要进行堆排序,先原创 2014-09-29 21:30:15 · 701 阅读 · 0 评论 -
排序--冒泡法
//冒泡排序#includeusing namespace std;void maopaopx(int a[],int n){ int temp; for(int i=0;i<n;i++)//i用来控制比较的次数 { for(int j=0;j<n-i;j++)//j用来进行前后两个数的比较,j比较的次数由i控制 { if(a[j]>a[j+1]原创 2014-07-27 23:01:18 · 794 阅读 · 0 评论 -
C++折半插入排序
//折半插入排序#includeusing namespace std;void BinInsertSort(int a[],int len){ int i,j,low,mid,high; int temp; for(i=1;i<len;i++) { if(a[i-1]>a[i]) { temp=a[i]; low=0; high=i-1; whi原创 2014-09-28 09:47:57 · 829 阅读 · 0 评论 -
C++直接插入排序
#includeusing namespace std;void InsertSort(int a[],int len){ int i,j; int temp; for(i=1;i<len;i++)//外循环表示要进行n-1趟排序 { if(a[i-1]>a[i]) { temp=a[i];//小值赋给temp j=i-1; do原创 2014-09-27 22:34:05 · 712 阅读 · 0 评论 -
哈希表初识--查找第一次只出现一次的字符
问题:在一个只有大小写字符串中查找第一个只出现一次的字母 input: aacddcvghhgii output: v 思路:使用hashtable 来使得时间复杂度为O(n) 创建hashtable原创 2014-08-12 01:13:35 · 847 阅读 · 0 评论 -
排序--快速排序法
//快速排序法#include using namespace std; void Qsort(int a[],int low,int high){ if(low>=high) { return; } int first=low;//0 int last=high;//8 int key原创 2014-07-27 22:57:36 · 779 阅读 · 0 评论 -
位图法排序
位图法:bitmap,就是用每一位来存放某种状态,适用于大规模数据,但数据状态又不是很多的情况。通常是用来判断某个数据存不存在的。对unsigned没有重复的数字进行排序,假设我们要对0-7内的5个元素(4,7,2,5,3)排序。那么我们就可以采用Bit-map的方法来达到排序的目的。要表示8个数,我们就只需要8个Bit(1Bytes),首先我们开辟1Byte的空间,将这些空间的所有Bit原创 2015-11-29 16:50:55 · 2960 阅读 · 0 评论