void partitionDecreasing(int value) { int * arr; printf("partitionDecreasing %d\n", value); arr = malloc(sizeof(int) * value); partition_dec(arr, 0, value); free (arr); }
void partition_dec(int * arr, int index, int n) { int test; if (n == 0) { printf("= "); printpartition(arr, index); return; } for (test = 1; test <= n; test++) { if ((index == 0) || (arr[index - 1] > test)) { arr[index] = test; partition_dec(arr, index + 1, n - test); } } }
/* return values: 0 == successful, 1 == error */ static int qsort_decreasing( struct cell v[], int left, int right ) { int pivot; int llen, rlen; int lleft, lright, rleft, rright; if ( pushstack( left )) return 1; if ( pushstack( right )) return 2; while ( stack_pointer != stack ) { if (popstack(&right)) return 3; if (popstack(&left )) return 4; if ( right - left > 0 ) { pivot = select_pivot( v, left, right ); partition_dec( v, &llen, &rlen, &lleft, &lright, &rleft, &rright, pivot, left, right ); if ( llen > rlen ) { if ( pushstack( lleft )) return 5; if ( pushstack( lright )) return 6; if ( pushstack( rleft )) return 7; if ( pushstack( rright )) return 8; } else{ if ( pushstack( rleft )) return 9; if ( pushstack( rright )) return 10; if ( pushstack( lleft )) return 11; if ( pushstack( lright )) return 12; } } } return 0; }