static int align_up(int **tbl, int len) { int i; int j; int cpt; cpt = 0; while (cpt < len) { i = cpt; while (i < ((len - 1) * len) + cpt) { j = i + len; while (j <= cpt + ((len - 1) * len)) { if (switch_values(tbl, i, j)) break ; j += len; } i += len; } cpt++; } return (0); }
//it will be used the first element of the array and then "dragged" for the right position int choose_pivot(int *vec, int begin, int end) { int i, pivot = begin; for (i = begin + 1; i <= end; i++) { // elements separation (left - lower than the pivot, right - bigger than the pivot if(vec[i] < vec[begin]) { pivot++; switch_values(&vec[i], &vec[pivot]); } } //stores in the pivot position the first element of the array switch_values(&vec[begin], &vec[pivot]); return pivot; }
static int align_down(int **tbl, int len) { int i; int j; int cpt; cpt = 0; while (cpt < len) { i = (len * (len - 1)) + cpt; while (i > cpt) { j = i - len; while (j >= cpt) { if (switch_values(tbl, i, j)) break ; j -= len; } i -= len; } cpt++; } return (0); }