sort.c
// first part is smaller
// second part is equal
// third part is greater
first part is smaller
second part is equal
third part is greater
first part is smaller second part is equal third part is greater
void partition(int array[], int n, int* firstEqual, int* firstGreater) {
	int pivot = array[0];
	int i;
	*firstEqual = 0;
	*firstGreater = 0;
	for (i = 0; i < n; ++i) {
		if (array[i] < pivot) {
			swap(array + *firstEqual, array + i);
			swap(array + i, array + *firstGreater);
			++*firstGreater;
			++*firstEqual;
		} else if (array[i] == pivot) {
			swap(array + *firstGreater, array + i);
			++*firstGreater;
		}
	}
}
void partition ( int array [ ] , int n , int * firstEqual , int * firstGreater ) { int pivot = array [ 0 ] ; int i ; * firstEqual = 0 ; * firstGreater = 0 ; for ( i = 0 ; i < n ; ++ i ) { if ( array [ i ] < pivot ) { swap ( array + * firstEqual , array + i ) ; swap ( array + i , array + * firstGreater ) ; ++ * firstGreater ; ++ * firstEqual ; } else if ( array [ i ] == pivot ) { swap ( array + * firstGreater , array + i ) ; ++ * firstGreater ; } } }
first part is smaller
second part is equal
third part is greater
first part is smaller second part is equal third part is greater
// loop through 0..n and process each element // element is smaller // swap the element with first equal // swap the first equal with first greater // swap the equal element with first greater