归并排序:(nlog(n) 小->大)1.将数组分成两部分2.将两部分分别排序3.将排完序的两部分合为一部分void merge_sort(int x,int y){ if(y-x = y || (p = y || (p = y) return; int k = a[x];...
分类:
编程语言 时间:
2015-02-24 13:44:24
阅读次数:
149
Counting Sort1. Counting Sort doesn't work for negative number.2. Counting Sort assumes that each element is SMALL INTEGER.3. Time Complexity is O(Max...
分类:
其他好文 时间:
2015-02-23 16:40:52
阅读次数:
118
上一题中用到了二分查找,而二分查找的前提条件就是原数据有序,故需要先进行排序。考虑用stl 中的sort函数对数据进行排序;由于不是基本数据类型而是自定义结构体不能自动排序,就需要给出排序规则。方法有两种:1.写 cmp函数bool cmp(stu a,stu b){return strcmp(a....
分类:
编程语言 时间:
2015-02-22 21:50:36
阅读次数:
250
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, inserti...
分类:
其他好文 时间:
2015-02-22 15:47:40
阅读次数:
163
原题:
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result ma...
分类:
其他好文 时间:
2015-02-21 22:19:37
阅读次数:
169
转自:http://www.wl566.com/biancheng/98907.htmlC++中sort的比较函数写法,有需要的朋友可以参考下。定义排序函数:方法1:声明外部比较函数bool Less(const Student& s1, const Student& s2){ return ...
分类:
编程语言 时间:
2015-02-21 18:49:09
阅读次数:
209
To Miss Our Children TimeTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 4075Accepted Submission(s...
分类:
其他好文 时间:
2015-02-20 23:08:09
阅读次数:
248
很简单。没什么好说的。主要学习了STL的find_if、binary_search、和sort函数。find_if函数原型为:template InputIterator find_if (InputIterator first, InputIterator last, UnaryPredic...
分类:
其他好文 时间:
2015-02-20 16:20:31
阅读次数:
199
描述参考整数排序方法,设计一种为字符串排序的算法,将字符串从小到大输出输入第一行为测试数据组数t, 后面跟着t组数据。每组数据第一行是n,表示这组数据有n行字符串,接下来是要排序的n行字符串。每行字符串的字符个数不会大于200, n 2 #include 3 void sort(char arr.....
分类:
编程语言 时间:
2015-02-19 21:50:58
阅读次数:
198
题意:给出一列数,先排序,再查找学习了sort函数,lower_bound函数sort:可以给任意对象排序(包括自己定义的)(前提是定义好了‘ 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int...
分类:
其他好文 时间:
2015-02-19 13:58:59
阅读次数:
117