Demo entry 6339869

xixihaha

   

Submitted by anonymous on Dec 26, 2016 at 11:42
Language: C. Code size: 633 Bytes.

#include <stdio.h>

void quickSort(int *a, int low, int high){
	int mid = a[low + high >> 1];
	int i = low, j = high, tmp;
	while(i <= j){
		while(a[i] < mid) ++ i;
		while(a[j] > mid) -- j;
		if(i <= j){
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
			++ i;
			-- j;
		}
	}
	if(low < j) quickSort(a, low, j);
	if(i < high) quickSort(a, i, high);
}

int a[100010];

int main(){
	int i, n;
	scanf("%d", &n);
	for(i = 1; i <= n; ++ i){
		scanf("%d", &a[i]);
	}
	quickSort(a, 1, n);
	printf("sorted:\n");
	for(i = 1; i <= n; ++ i){
		printf("%d", a[i]);
		printf(i == n ? "\n" : " ");
	}
	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).