static int partition (int *l, int low, int high) { int c; int middle; int k = get_pivot (low, high); int pivot = l[k]; swap (&l[low], &l[k]); // move pivot out of array to order c = low + 1; middle = high; while (c <= middle) // run the array { while ((c <= high) && (l[c] <= pivot)) // before pivot c++; while ((middle >= low) && (l[middle] > pivot)) // after pivot middle--; if (c < middle) swap (&l[c], &l[middle]); } swap (&l[low], &l[middle]); // bring the pivot to its place return middle; }
static void handle_sort(t_heap **a_heap, t_heap **b_heap, t_opt *opt, int *sorted_tab) { int nbr_elem_lst; int i; i = 1; nbr_elem_lst = get_nbr_elem(a_heap); opt->step = get_step(nbr_elem_lst); while (is_sort(a_heap) != 1) { opt->split = get_pivot(sorted_tab, nbr_elem_lst, opt->step, i); push_step_to_b(opt, nbr_elem_lst, i); sort_step(a_heap, b_heap, opt); put_max_in_last_pos(opt); ++i; } }
ring_elem DetComputation::bareiss_det() { // Computes the determinant of the p by p matrix D. (dense form). int sign = 1; size_t pivot_col; ring_elem pivot = R->from_long(0); ring_elem lastpivot = R->from_long(0); for (size_t r=p-1; r>=1; --r) { R->remove(lastpivot); lastpivot = pivot; if (!get_pivot(D, r, pivot, pivot_col)) // sets pivot_col and pivot { // Remove the rest of D. for (size_t i=0; i<=r; i++) for (size_t j=0; j<=r; j++) R->remove(D[i][j]); R->remove(lastpivot); return R->from_long(0); } for (size_t i=0; i<r; i++) gauss(D,i,r,pivot_col,lastpivot); if (((r + pivot_col) % 2) == 1) sign = -sign; // MES: do I need to rethink this logic? for (size_t c=0; c<=r; c++) if (c != pivot_col) R->remove(D[r][c]); else D[r][c] = ZERO_RINGELEM; } R->remove(pivot); R->remove(lastpivot); ring_elem r = D[0][0]; D[0][0] = ZERO_RINGELEM; if (sign < 0) R->negate_to(r); return r; }