Exemplo n.º 1
0
void subsort(int s, int t){
	int i=s, j=t, temp;
	int x = A[s];	// ピボットは何でもいいので一番最初の要素を使う.
	do{
		// x(ピボット)を基準にして2つのクラスに分ける.
		while(A[i] < x){
			i=i+1;
		}
		while(x < A[j]){
			j=j-1;
		}
		if(i<=j){
			temp = A[i];
			A[i] = A[j];
			A[j] = temp;
			i=i+1;
			j=j-1;
		}
	}while(i<j);

	if(s<j){
		subsort(s,j);	// x以下のクラスを再帰的にソート.
	}
	if(i<t){
		subsort(i,t);	// x以上のクラスを再帰的にソート.
	}
}
Exemplo n.º 2
0
 void run()
 {
     unsigned s;
     unsigned n;
     if (waitForWork(s,n))
         subsort(s,n);
 }
Exemplo n.º 3
0
void quicksort(){
	subsort(0,N);
}