Пример #1
0
void quicksort_recursive(uint32_t n, uint32_t *in, uint32_t *out)
{
    (void) in;

    if(n <= 1)
        return;
    
    uint32_t store_idx = quicksort_partition_helper(n, out);
    
    quicksort_recursive(store_idx, NULL, out);
    quicksort_recursive(n - store_idx - 1, NULL, &out[store_idx + 1]);
}
Пример #2
0
			static void sort(T& array, unsigned int length)
			{
				if (length < STACK_LIMIT)
					quicksort_recursive(array, 0, length);
				else
					quicksort(array, length);
			}
void quicksort_recursive(int *data,int head,int rear){
	if(head>=rear)
		return;
	int pivot=data[rear-1];
	int i=head,j=rear-2;
	while(i<=j){
		while(data[i]<pivot && i<rear)
			i++;
		while(data[j]>=pivot && j>=0)
			j--;
		if(i<j)
			swap(data,i,j);
	}
	swap(data,i,rear-1);
	quicksort_recursive(data,head,i);
	quicksort_recursive(data,i+1,rear);
}
Пример #4
0
			static void quicksort_recursive(T& array, unsigned int left, unsigned int right)
			{
				if (left < right)
				{
					unsigned int m = left;

					for (unsigned int i = left + 1; i < right; i++)
					{
						if (array[i] < array[left])
							std::swap(array[++m], array[i]);
					}

					std::swap(array[left], array[m]);

					quicksort_recursive(array, left, m);
					quicksort_recursive(array, m + 1, right);
				}
			}
int main(){
	/*
	时间复杂度:O(n)
	空间复杂度:O()
	适用于属于一定范围内的数的排序。
	思路:。
	*/
	int data[]={60,2,97,78,0,84,68,23,48,22,63,31,43,42,82,9,
		57,21,42,62,83,98,64,72,96,31,76,13,70,49,10,60,72,36,
		26,4,56,54,13,9,98,45,61,90,88,80,30,50,77,83,};
	int size=sizeof data/sizeof *data;
	#ifdef USE_RECURSIVE
	printf("use recursive\n");
	quicksort_recursive(data,0,size);
	#elif defined(USE_NONRECURSIVE)
	printf("use non recursive\n");
	quicksort_nonrecursive(data,size);
	#endif
	displayoutcome(data,size);
	return 0;
}