aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-21 15:13:16 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-21 15:13:16 +0100
commite80d3b18ebffc4eb882e9ffc474c7251aae52b51 (patch)
tree519dc4bee330b82d6fdf7f8e78c0dcbfd3374d8c
parentfe7b8336097b2935ae340ce43034a93d6b096b13 (diff)
downloadpush_swap-e80d3b18ebffc4eb882e9ffc474c7251aae52b51.tar.gz
push_swap-e80d3b18ebffc4eb882e9ffc474c7251aae52b51.tar.bz2
push_swap-e80d3b18ebffc4eb882e9ffc474c7251aae52b51.zip
algo working but there is room for optimisation
-rw-r--r--Makefile4
-rw-r--r--src/push_swap/sort.c8
2 files changed, 7 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 2e08fe0..e5d5cf2 100644
--- a/Makefile
+++ b/Makefile
@@ -36,11 +36,11 @@ all: libft_all $(CHECKER_NAME) $(PUSH_SWAP_NAME)
$(CHECKER_NAME): CCFLAGS += -I$(CHECKER_DIR)
$(CHECKER_NAME): $(CHECKER_OBJ) $(CHECKER_HEADER) $(LIBFT_DIR)/libft.a
- $(CC) $(LDFLAGS) -o $@ $(CHECKER_OBJ)
+ $(CC) -o $@ $(CHECKER_OBJ) $(LDFLAGS)
$(PUSH_SWAP_NAME): CCFLAGS += -I$(PUSH_SWAP_DIR)
$(PUSH_SWAP_NAME): $(PUSH_SWAP_OBJ) $(PUSH_SWAP_HEADER) $(LIBFT_DIR)/libft.a
- $(CC) $(LDFLAGS) -o $@ $(PUSH_SWAP_OBJ)
+ $(CC) -o $@ $(PUSH_SWAP_OBJ) $(LDFLAGS)
%.o: %.c
$(CC) $(CCFLAGS) -c -o $@ $<
diff --git a/src/push_swap/sort.c b/src/push_swap/sort.c
index 2e5c7fb..4804591 100644
--- a/src/push_swap/sort.c
+++ b/src/push_swap/sort.c
@@ -57,7 +57,7 @@ static void push_swap_qsort_partition(t_stack *main, t_stack *tmp, int main_fram
frame_len = frame_length(main, main_frame) - 1;
while (frame_len > 0)
{
- if (stack_peek(main) < pivot)
+ if (main->tag == STACK_A ? (stack_peek(main) < pivot) : (stack_peek(main) > pivot))
stack_push_to_print(main, tmp);
else
{
@@ -90,20 +90,22 @@ static void push_swap_qsort_rec(t_stack *main, t_stack *tmp, int main_frame, int
return ;
if (frame_length(main, main_frame) == 2)
{
- if (stack_peek(main) > main->elements[stack_length(main) - 1])
+ if (main->tag == STACK_A ? stack_peek(main) > main->elements[stack_length(main) - 1] :
+ stack_peek(main) < main->elements[stack_length(main) - 1])
stack_swap(main);
return ;
}
push_swap_qsort_partition(main, tmp, main_frame);
+
push_swap_qsort_rec(tmp, main, tmp_frame, stack_length(main));
stack_push_to_print(main, tmp);
push_swap_qsort_rec(main, tmp, main_frame, stack_length(tmp));
+ stack_push_to_print(tmp, main);
int tmp_frame_len = frame_length(tmp, tmp_frame);
while (tmp_frame_len != 0)
{
- /* stack_reverse_rotate_print(tmp); */
stack_push_to_print(tmp, main);
tmp_frame_len--;
}