summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2024-04-17 09:48:09 +0200
committerDominik Kaiser2024-04-17 09:48:09 +0200
commitc0537681539794755df7b0be610b0fa7706411ba (patch)
tree27e85b0a2b596426fea12cca24919c105e29eb18
parent5ae6bcfed569e323a6a628636f4fcf92740d2ae0 (diff)
downloadpush_swap-c0537681539794755df7b0be610b0fa7706411ba.tar.gz
push_swap-c0537681539794755df7b0be610b0fa7706411ba.zip
Change to 3-way radixsort
Instead of splitting into 2 sets, radixsort will split into 3. Currently one set is half and the other two each a quarter. Probably the efficiency could be increased by 3 equal partitions. Will look into that later.
-rw-r--r--sorting.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/sorting.c b/sorting.c
index 422625e..215f4a4 100644
--- a/sorting.c
+++ b/sorting.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/13 15:04:19 by dkaiser #+# #+# */
-/* Updated: 2024/04/16 17:54:16 by dkaiser ### ########.fr */
+/* Updated: 2024/04/17 09:30:37 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,17 +33,33 @@ static void radixsort(t_psdata *data, int bit)
{
int i;
int size;
+ int ctr;
i = 0;
+ ctr = 0;
size = data->a->size;
while (i < size)
{
if (data->a->size && ((data->a->stack[0] >> bit) & 1) == 0)
- run_command(data, PB);
+ {
+ if (((data->a->stack[0] >> bit )& 2) == 0)
+ run_command(data, PB);
+ else
+ {
+ run_command(data, PB);
+ run_command(data, RB);
+ ctr++;
+ }
+ }
else if (data->a->size > 1)
run_command(data, RA);
i++;
}
+ while (ctr--)
+ {
+ run_command(data, RRB);
+ run_command(data, PA);
+ }
while (data->b->size > 0)
run_command(data, PA);
if (!is_sorted(data->a))