stooge排序是一种递归排序算法,这种排序算法不仅慢于一般的有效排序算法(如:插入排序,合并排序,堆排序和快速排序),甚至慢于冒泡排序。是一种简单但低效的排序算法。...
分类:
其他好文 时间:
2014-06-07 01:26:17
阅读次数:
173
【题目】
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, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and...
分类:
其他好文 时间:
2014-06-07 01:17:49
阅读次数:
269
Java线程的join方法可用于暂停当前线程的执行直至目标线程死亡。Thread中一共有三个join的重载方法。
public final void join():该方法将当前线程放入等待队列中,直至被它调用的线程死亡为止。如果该线程被中断,则会抛出InterruptedException异常。
public final synchronized void join(long...
分类:
编程语言 时间:
2014-06-05 03:41:18
阅读次数:
243
An iterative way of writing merge sort:
#include
using namespace std;
void merge(int A[], int l, int r, int e, int B[]) {
int i = l, j = r, k = l;
while (i<r && j A[j]) B[k++] =...
分类:
其他好文 时间:
2014-06-03 02:33:24
阅读次数:
215
An iterative way of writing quick sort:
#include
#include
#include
using namespace std;
void quickSort(int A[], int n) {
stack> stk;
stk.push(make_pair(0, n-1));
while (!stk.empty()) {
pair ...
分类:
其他好文 时间:
2014-06-03 00:16:43
阅读次数:
357
进来复习了一下C语言指针,一直没有写过太多关于函数指针的代码,而且对回调函数的理解一直都是在理论上,基本上没有太写过关于它的代码,进来得空,写了一个小程序加深下自己对回调函数和函数指针的理解。
问题描述: 编写一个sort()函数,使它能够对任何类型的数组元素进行排序。
下面是我写的代码:
/*
使用函数指针的回调函数技巧,设计一个能排序int 和char 数组的sort()函...
分类:
其他好文 时间:
2014-06-02 23:16:49
阅读次数:
471
当您使用资源浏览器查看文件时,您能够随心所欲的按名称、大小、类型及改动日期不同的列对文件进行大小排序。.Net提供的ListView组件没有直接提供这样的功能,但要实现并不难。
ListView.Sort()方法的功能是“对列表视...
分类:
其他好文 时间:
2014-06-02 00:03:13
阅读次数:
241
3. 线程控制
1). 线程属性
目标:可以设置 线程的 detached/join 状态,线程栈的大小和最低地址等属性。
detached/join 状态的区别:
当线程处于 分离状态(detached)时,线程结束时,os立即回收资源。主线程不可以调用pthread_join获取线程退出时的返回值。
当线程...
分类:
编程语言 时间:
2014-06-01 17:51:03
阅读次数:
508
接口是一组对类的需求描述,这些类要遵从接口描述的统一格式进行定义。
“如果你的类遵从某个特定接口,那么我就履行这项服务”。
一个具体的例子:Arrays类中的sort方法承诺可以对对象数组进行排序,但要求满足一个前提:对象所属的类必须实现了Comparable接口。
如:
class Employee implements Comparable{
private doubl...
分类:
编程语言 时间:
2014-06-01 15:42:18
阅读次数:
349
对于不同文件中的数据,有时候有对应关系,需要进行连接(join),获得一个新的文件以便进行分析。比如有两个输入文件a.txt,b.txt,其中的数据格式分别如下
1 a
2 b
3 c
4 d
1 good
2 bad
3 ok
4 hello
需要将其连接成一个新的如下的文件:
a good
b bad
c ok
d hello
处理步骤可以分成两步:
1.map阶段,将两个输入文件...
分类:
其他好文 时间:
2014-06-01 09:05:01
阅读次数:
325