代码如下: 1 public class MergeSort { 2 3 public static void sort(int [] A,int p, int r) 4 { 5 if(p X)16 j--;17 ...
分类:
编程语言 时间:
2015-01-29 23:49:57
阅读次数:
218
数组中有一个sort方法,用于数组排序,sort可以接收一个参数,指明比较函数。定义比较函数 //比较函数 function compareFun(value1,value2){ if(value1 > value2){ return 1; }e...
分类:
编程语言 时间:
2015-01-29 21:05:21
阅读次数:
215
原题地址链表归并排序真是恶心的一道题啊,哇了好多次才过。代码: 1 void mergeList(ListNode *a, ListNode *b, ListNode *&h, ListNode *&t) { 2 h = t = NULL; 3 while (a && b) { 4 ...
分类:
其他好文 时间:
2015-01-29 20:59:24
阅读次数:
155
原题地址心得:有关链表的题目,多用中间变量,代码写得清晰一点,适当注释代码: 1 ListNode *insertionSortList(ListNode *head) { 2 if (!head) return NULL; 3 4 ListNode...
分类:
其他好文 时间:
2015-01-29 19:09:17
阅读次数:
102
四、归并排序
1、基本思想:归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的。然后再把有序子序列合并为整体有序序列。
2、实例
3、java实现
1 packagecom.sort;
2
3 //稳定
4 public class 归并排序{
5 public static...
分类:
编程语言 时间:
2015-01-29 17:45:03
阅读次数:
213
冒泡算法 static void bubble_sort(int[] unsorted) { for (int i = 0; i unsorted[j]) { int te...
分类:
编程语言 时间:
2015-01-29 17:30:50
阅读次数:
164
#include #include #include #include #include using namespace std;int cmp(const string p,const string q){ return p.length()> str[i]; sort(str, str+n, c...
分类:
其他好文 时间:
2015-01-29 12:23:53
阅读次数:
162
1.
求夹角时候的tan值可以用x/y, 这样比较哪个更大,则夹角距x正向的距离更小. 2.
全局变量放在主函数外面可以减小运行时间。 3.
qsort中的size如果是结构体的话最好用结构体第一个单元,如sizeof(num[0])。 4.
有大量比较时候尽量用sort、qsort不稳定,sort...
分类:
其他好文 时间:
2015-01-29 12:20:03
阅读次数:
164
#include "iostream"#include "cmath"using namespace std;int sort(int a[],int n){ int temp,all=0; for(int i=0;ia[j]) {temp=a[i];a[i]=a[j];a[j]=temp;} } ...
分类:
其他好文 时间:
2015-01-29 12:10:15
阅读次数:
115
题目链接:https://oj.leetcode.com/problems/sort-colors/
题目信息:
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 ...
分类:
其他好文 时间:
2015-01-29 09:28:58
阅读次数:
109