From: Dominik Kaiser Date: Wed, 17 Apr 2024 08:51:01 +0000 (+0200) Subject: Add presorting X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=61c619f2d24cadd53defe1cfa74b71f644c49010;p=42%2Fpush_swap.git Add presorting All entries that are not in order will be pushed into b. If the entry is larger than our pivot, it will be pushed to the bottom, else the top of b. --- diff --git a/sorting.c b/sorting.c index 8f5d31f..ca21757 100644 --- a/sorting.c +++ b/sorting.c @@ -6,13 +6,38 @@ /* By: dkaiser a->size; + pivot = size / 2; + max = data->a->stack[0]; + while (size--) + { + if (data->a->stack[0] < max) + { + run_command(data, PB); + if (data->b->stack[0] > pivot) + run_command(data, RB); + } + else + { + max = data->a->stack[0]; + run_command(data, RA); + } + } +} +void stack_sort(t_psdata *data) +{ + presort(data); }