From b8adc8c68153186b5bc6ef71e6401ec676aee1b2 Mon Sep 17 00:00:00 2001 From: Ana Laura Da Silva Volkmann Date: Fri, 19 Jul 2024 17:14:35 +0100 Subject: [PATCH] push_swap --- ft_big_sort.c | 2 +- push_swap.c | 2 +- set_cost_of.c | 16 ++++++++++------ set_targets.c | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ft_big_sort.c b/ft_big_sort.c index 23a8867..c2cb82e 100644 --- a/ft_big_sort.c +++ b/ft_big_sort.c @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/10 12:54:58 by ana-lda- #+# #+# */ -/* Updated: 2024/07/19 11:18:38 by ana-lda- ### ########.fr */ +/* Updated: 2024/07/19 17:13:32 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/push_swap.c b/push_swap.c index b9e9b34..4926f10 100644 --- a/push_swap.c +++ b/push_swap.c @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 14:18:34 by ana-lda- #+# #+# */ -/* Updated: 2024/07/17 14:27:53 by ana-lda- ### ########.fr */ +/* Updated: 2024/07/19 15:12:16 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/set_cost_of.c b/set_cost_of.c index a1e5886..30a9a80 100644 --- a/set_cost_of.c +++ b/set_cost_of.c @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/16 13:38:28 by ana-lda- #+# #+# */ -/* Updated: 2024/07/19 13:58:04 by ana-lda- ### ########.fr */ +/* Updated: 2024/07/19 15:57:33 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,13 +44,17 @@ void refine_cost(t_stack *temp, t_stack **stack_a, t_stack **stack_b) if (temp->above_median && temp->target->above_median) { - temp->cost -= (temp->index < temp->target->index) ? temp->index : temp->target->index; + if (temp->index < temp->target->index) + temp->cost -= temp->index; + else + temp->cost -= temp->target->index; } - else + else if (!(temp->above_median) && (!temp->target->above_median)) { - int cost_a = size_a - temp->index; - int cost_b = size_b - temp->target->index; - temp->cost -= (cost_a < cost_b) ? cost_a : cost_b; + if (size_a - temp->index < size_b - temp->target->index) + temp->cost -= size_a - temp->index; + else + temp->cost -= size_b - temp->target->index; } } diff --git a/set_targets.c b/set_targets.c index f7de843..dc921cf 100644 --- a/set_targets.c +++ b/set_targets.c @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/13 14:26:47 by ana-lda- #+# #+# */ -/* Updated: 2024/07/19 12:07:23 by ana-lda- ### ########.fr */ +/* Updated: 2024/07/19 16:47:21 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,4 +85,4 @@ void update_stack_nodes(t_stack **stack_a, t_stack **stack_b, int flag) set_target_in_a(stack_a, stack_b); cost_of_b(stack_a, stack_b); } -} \ No newline at end of file +}