[ create a new paste ] login | about

Link: http://codepad.org/rKtQ7Wrg    [ raw code | output | fork ]

C, pasted on Dec 27:
#include <stdio.h>

void array_csort(int a[], int n){
	int i, j, k, cs[3] = { 0, 0, 0 };
	for(i = 0; i < n; ++i)
		++cs[a[i]];
	
	for(k = i = 0; i < 3; ++i){
		for(j = 0; j < cs[i]; ++j)
			a[k++] = i;
	}
}

int main(void) {
	int i;
	int a[] = { 2, 1, 2, 1, 2, 2, 0, 2, 2, 1, 2 };	
	int n   = sizeof(a)/sizeof(a[0]);

	array_csort(a, n);
	for(i = 0; i < n; ++i)
		printf("%d ", a[i]);
	return 0;
}


Output:
1
0 1 1 1 2 2 2 2 2 2 2 


Create a new paste based on this one


Comments: