类的适配器模式classCIntegerSortAdapter:DoubleSort,Sortable{publicint[]Sort(int[]number){double[]dnum=newdouble[number.Length];int[]inum=newint[number.Length]...
分类:
其他好文 时间:
2014-06-11 08:04:50
阅读次数:
242
众所周知,Std::sort()是一个非常快速的排序算法,它基于快排,但又有所修改。一般来说用它就挺快的了,代码一行,时间复杂度O(nlogn)(难道不是大叫一声“老子要排序!!”就排好了么。。。)。我们也知道,不基于比较的排序可以达到O(n),比如说基数排序。什么,它是O(n
* log(10.....
分类:
其他好文 时间:
2014-06-10 00:04:07
阅读次数:
326
代码#!/usr/bin/python#-*-coding:utf-8-*-#----------------------------------------------------------------------------------------#
to_do : bubble sort#....
分类:
编程语言 时间:
2014-06-08 23:51:58
阅读次数:
461
原题地址:https://oj.leetcode.com/problems/sort-colors/题意:Given
an array withnobjects colored red, white or blue, sort them so that objects of
the same col...
分类:
编程语言 时间:
2014-06-08 20:56:32
阅读次数:
394
java中的ArrayList需要通过collections类的sort方法来进行排序如果想自定义排序方式则需要有类来实现Comparator接口并重写compare方法调用sort方法时将ArrayList对象与实现Commparator接口的类的对象作为参数示例://
外部类的方式import ...
分类:
其他好文 时间:
2014-06-08 19:10:21
阅读次数:
221
下面说说split函数的用法
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')#split('.',1) use '.' split one time
return words
def sort_words(wo...
分类:
编程语言 时间:
2014-06-08 18:19:21
阅读次数:
336
在前几个章节中使用了Comparable作为比较函数。比如对于字符串,就是按字母表的顺序进行排序。有时候想要换一种比较方式,该怎么实现呢?
在Java中可以使用Comparator比较器,以下代码展示了字符串之间不同的比较方式。
String[] a;
...
Arrays.sort();
...
Arrays.sort(a, String.CASE_INSENSITI...
分类:
其他好文 时间:
2014-06-08 15:37:08
阅读次数:
201
排序算法是我们工作中使用最普遍的算法,常见的语言库中基本都会有排序算法的实现,比如c标准库的qsort,stl的sort函数等。本文首先介绍直接插入排序,归并排序,堆排序,快速排序和基数排序等比较排序算法,然后介绍计数排序,基数排序等具有线性时间的排序算法。本文主要讨论算法的实现方法,并不会过多介绍...
分类:
其他好文 时间:
2014-06-07 21:23:31
阅读次数:
348
原文:浅谈算法和数据结构: 四
快速排序上篇文章介绍了时间复杂度为O(nlgn)的合并排序,本篇文章介绍时间复杂度同样为O(nlgn)但是排序速度比合并排序更快的快速排序(Quick
Sort)。快速排序是20世纪科技领域的十大算法之一 ,他由C. A. R. Hoare于1960年提出的一种划分交...
分类:
其他好文 时间:
2014-06-07 20:15:43
阅读次数:
362
Given an array withnobjects colored red, white
or blue, sort them so that objects of the same color are adjacent, with the
colors in the order red, wh...
分类:
其他好文 时间:
2014-06-07 20:11:53
阅读次数:
234