コード例 #1
0
ファイル: sort.c プロジェクト: louisdespi/push_swap
int		get_median_partition(t_list *lst, int size_partition)
{
	int		min;
	int		max;
	int		*t;
	int		size;
	int		median;

	size = build_table(lst, &t); //penser au pattern singleton
	hidden_quicksort(t, 0, size - 1);
	get_max_partition(lst, size_partition, &max);
	get_min_partition(lst, size_partition, &min);
	median = get_median(t, get_index_array(t, min, size), get_index_array(t, max, size));
	return (median);
}
コード例 #2
0
ファイル: 26.class.gslice.cpp プロジェクト: Quna/mspdev
static void
test_gslice (std::size_t  start,
             const char  *sizes,
             const char  *strides)
{
    const std::valarray<std::size_t> asizes (make_array (sizes));
    const std::valarray<std::size_t> astrides (make_array (strides));

    const std::gslice gsl (start, asizes, astrides);

    const std::valarray<std::size_t> indices = get_index_array (gsl);

    std::size_t maxinx = 0;

    for (std::size_t i = 0; i != indices.size (); ++i)
        if (maxinx < indices [i])
            maxinx = indices [i];

    std::valarray<std::size_t> va (maxinx + 1);
    for (std::size_t i = 0; i != va.size (); ++i)
        va [i] = i;

    for (int i = 0; i != 3; ++i) {
        // repeat each test three to verify that operator[](gslice)
        // doesn't change the observable state of its argument and
        // that the same result is obtained for a copy of gslice

        const std::valarray<std::size_t> array_slice =
            i < 2 ? va [gsl] : va [std::gslice (gsl)];

        bool equal = array_slice.size () == indices.size ();

        rw_assert (equal, 0, __LINE__,
                   "size() == %zu, got %zu\n",
                   indices.size (), array_slice.size ());

        if (equal) {
            for (std::size_t j = 0; j != array_slice.size (); ++j) {

                equal = array_slice [j] == va [indices [j]];

                rw_assert (equal, 0, __LINE__,
                           "mismatch at %u, index %u: expected %u, got %u\n",
                           j, indices [j], va [indices [j]],
                           array_slice [j]);
            }
        }
    }
}