在STL中,排序是个很重要的话题。1.algorithm 里的sort()只接收RandomAccessIterator用于像vector,dequeue的排序2.像set,map,这种关联式容器,本身就由RBTree维护了有序,只要遍历一遍就行了。3.而list比较特殊一点,由于只有Bidirec...
分类:
其他好文 时间:
2014-06-28 22:09:39
阅读次数:
209
1- "原地"排序-转换后替换>>> list = [2,1,3]>>> list.sort()>>> list[1, 2, 3]降序 reverse = True>>> list.sort(reverse = True)>>> list[3, 2, 1, 1]2- "复制"排序-转换然后返回>>>...
分类:
编程语言 时间:
2014-06-28 20:04:47
阅读次数:
299
Sort a linked list using insertion sort.单链表的插入排序, 考查的时单链表指针的断开和插入操作#include #include #include using namespace std;struct ListNode{ int val; List...
分类:
其他好文 时间:
2014-06-21 12:26:49
阅读次数:
206
一、基本原理
Python中一切都是对象,变量中存放的是对象的引用。这是一个普遍的法则。我们举个例子来说,Python是如何来处理的。
Python代码
x = 'blue'
y = 'green'
z = x
当python执行上面第一句的时候,会在heap中首先创建一个str对象,其文本内容为blue,同时还创建一个名为x的对象引用,x...
分类:
编程语言 时间:
2014-06-18 07:19:52
阅读次数:
314
分治法的典例
当练手了
神奇的是,使用inplace_merge按说应该是O(n)的算法,但是用sort nlogn的算法反而更快
先上快排版
#include
#include
#include
#include
#include
using namespace std;
const int SIZE = 10000+10;
const double INF = 1...
分类:
其他好文 时间:
2014-06-18 07:17:22
阅读次数:
170
原题如下,意思就是说无序数组(由0,1,2组成),一遍扫描,把数组整理成0,1,2这样的序列。
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red,...
分类:
其他好文 时间:
2014-06-18 07:12:43
阅读次数:
174
[1.1]使用库语言排序算法本文地址: http://blog.csdn.net/caroline_wendy如果不缺少内存, 可以直接使用库的排序算法.使用库语言的排序程序:C语言性能最好的算法是快速排序(quick sort).C++性能最好的是集合(set)的排序算法.C语言代码:/*
* main.cpp
*
* Created on: 2014.6.12
* Auth...
分类:
其他好文 时间:
2014-06-18 00:40:02
阅读次数:
269
归并排序(merging sort): 包含2-路归并排序, 把数组拆分成两段, 使用递归, 将两个有序表合成一个新的有序表.归并排序(merge sort)的时间复杂度是O(nlogn), 实际效果不如快速排序(quick sort)和堆排序(heap sort),但是归并排序是稳定排序, 而.....
分类:
其他好文 时间:
2014-06-17 23:47:38
阅读次数:
299
以下code 来源于 啊哈磊大神~ =-=你可以百度 --- 啊哈磊 ---都是 关于heap的一些操作...向下调整:-> 1 void siftdown(int i) //传入一个需要向下调整的结点编号i,这里传入1,即从堆的顶点开始向下调整 2 { 3 int t,flag=0;//...
分类:
其他好文 时间:
2014-06-17 23:41:18
阅读次数:
368
归并排序(merging Sort) 详解 及 代码本文地址: http://blog.csdn.net/caroline_wendy归并排序(merging sort): 包含2-路归并排序, 把数组拆分成两段, 使用递归, 将两个有序表合成一个新的有序表.归并排序(merge sort)的时间复杂度是O(nlogn), 实际效果不如快速排序(quick sort)和堆排序(heap sort)...
分类:
其他好文 时间:
2014-06-17 16:19:56
阅读次数:
232