def select_sort(list):
for i in range(len(list)):
position = i
for j in range(i,len(list)):
if list[position] > list[j]:
position = j
temp = list[i]
list[i] = list[position]
list[pos...
分类:
编程语言 时间:
2014-08-12 17:25:34
阅读次数:
236
def insert_sort(list):
for i in range(len(list)):
while i > 0 and list[i] < list[i-1]:
temp = list[i]
list[i] = list[i-1]
list[i-1] = temp
i = i-1...
分类:
编程语言 时间:
2014-08-12 17:25:24
阅读次数:
269
1、List.Sort(泛型Comparison)法此方法的参数是Comparison类型,其实是一个包含两个参数的委托,因此使用此方法,我们只需要定义一个委托,其两个参数均为Student类型,在委托实现的方法比较两个Student对象的Age属性即可。
usingSystem;
usingSystem.Collections.Generic;
usi..
分类:
其他好文 时间:
2014-08-12 13:51:55
阅读次数:
229
Problem:
Sort a linked list in O(n log n)
time using constant space complexity.
解题思路:
首先,时间复杂度能达到O(nlgn)的排序算法,常见的有3种:堆排序、归并排序和快速排序,
而对于链表,用堆排序显然不太可能,所以,我们可用归并或者是快排.由于合并...
分类:
其他好文 时间:
2014-08-12 00:45:13
阅读次数:
217
Sort ColorsGiven an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the or...
分类:
其他好文 时间:
2014-08-12 00:09:03
阅读次数:
154
http://poj.org/problem?id=2549
维基百科有3Sum算法:https://en.wikipedia.org/wiki/3SUM
sort(S);
for i=0 to n-3 do
a = S[i];
k = i+1;
l = n-1;
while (k<l) do
b = S[k];
c = ...
分类:
其他好文 时间:
2014-08-11 21:23:53
阅读次数:
356
function quick_sort(list, head, tail) if tail > head then i = head j = tail tmp = list[i] --取第一个元素用于比较 同时腾出第一个位置 while i i do if list[j] tmp then li.....
分类:
其他好文 时间:
2014-08-11 20:59:12
阅读次数:
274
快速排序是一种效率比较高的算法,算法的思想是取出待排序中的一个元素,想办法将小于他的元素交换到他的左边,大于他的元素交换于他的右侧,然后对左右两侧再分别递归进行上述过程,直到左右两侧的元素只有一个。从而实现了整体的排序。c++实现的代码如下:
//快速排序(递归)
template
void quick_sort(T *arr,int b,int e)
{
if(b<e)
{ ...
分类:
其他好文 时间:
2014-08-11 15:00:42
阅读次数:
210
1、用sort对结构体中字符串进行二级排序
#include
#include
using namespace std;
struct s
{
int d;
char c[10];
}ss[15];
bool cmp(s a,s b)
{
if(strcmp(a.c,b.c)!=0)
...
分类:
其他好文 时间:
2014-08-11 06:19:01
阅读次数:
171
#include //从小到大排列#include#includeusing namespace std;int main(){ int i,x; vectormy ; for(i=1;i>x; my.push_back(x); } sort(my.begin(),my.end()); f...
分类:
其他好文 时间:
2014-08-10 18:34:30
阅读次数:
188