Collections是JDK针对集合提供的一个工具类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作。1、搜索如可以使用Collections提供的二分查找方法binarySearch()2、排序如可以使用Collections.sort()对List进行了排序3、线程安全化使用...
分类:
其他好文 时间:
2014-06-09 21:34:32
阅读次数:
175
#include #define SIZE 8void bubble_sort(int a[],
int n);void bubble_sort(int a[], int n) { int i, j, temp; for (j = 0; j a[i +
1]) { ...
分类:
其他好文 时间:
2014-06-09 20:45:16
阅读次数:
255
Sort a linked list in O(n log n) time using
constant space
complexity.一谈到时间复杂度O(nlogn),立即联想到以下3种排序方法:1.归并排序(基于分治):时间复杂度O(nlogn),归并排序的最好、平均、最坏时间复杂度没有差别...
分类:
其他好文 时间:
2014-06-09 20:37:31
阅读次数:
244
代码#!/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
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