Sort
文章平均质量分 77
neostar2008
这个作者很懒,什么都没留下…
展开
-
Quick Sort
选第一个数为pivot bool Cmp(int & a, int & b) { if(a >= b) return true; return false; } template int Partition(vector & f, int start, int finish, bool (cmp)(T & a, T & b)) { T key = f[start]; int left原创 2012-06-24 21:01:55 · 258 阅读 · 0 评论 -
Merge Sort
The basic idea of Merge Sort can be outlined as follows: 1. Check to see if the vector is empty or has only one element. If so, it must already be sorted, and the function can return without doin原创 2012-06-14 21:32:05 · 319 阅读 · 0 评论 -
Heap & HeapSort (using template)
维基百科的讲解: http://en.wikipedia.org/wiki/Binary_heap 先列出int型的 heap.h 和 heap.cpp,底层用vector实现,包含大顶堆(MaxHeap)和小顶堆(MinHeap)两个类 头文件 #ifndef _HEAP_H_ #define _HEAP_H_ #include using namespace std; cl原创 2012-07-20 22:28:45 · 694 阅读 · 0 评论