From 7a6533373ab9b0dd075f995c98dcf332a7876fac Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 10 Sep 2021 10:54:12 +0200 Subject: Updated to norm v3 --- src/push_swap/sort.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/push_swap/sort.c') diff --git a/src/push_swap/sort.c b/src/push_swap/sort.c index b6113e9..588dc54 100644 --- a/src/push_swap/sort.c +++ b/src/push_swap/sort.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/19 09:12:02 by cacharle #+# #+# */ -/* Updated: 2020/07/21 11:43:00 by charles ### ########.fr */ +/* Updated: 2021/09/10 10:48:01 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,6 +47,14 @@ static int frame_length(t_stack *st, int frame_index) /* stack_swap_print(main); */ /* } */ +static int not_a_ternary(bool cond, int x, int y) +{ + if (cond) + return (x); + else + return (y); +} + /* ** main : stack to sort ** tmp : temporary stack used to store pivot > values @@ -70,7 +78,7 @@ static void push_swap_qsort_partition(t_stack *main, t_stack *tmp, int main_frame) { int pivot; - int hidden_count; + int hidden_count; int frame_len; pivot = stack_peek(main); @@ -79,8 +87,8 @@ static void push_swap_qsort_partition(t_stack *main, t_stack *tmp, frame_len = frame_length(main, main_frame) - 1; while (frame_len > 0) { - if (main->tag == STACK_A ? - (stack_peek(main) < pivot) : (stack_peek(main) > pivot)) + if (not_a_ternary(main->tag == STACK_A, + stack_peek(main) < pivot, stack_peek(main) > pivot)) stack_push_to_print(main, tmp); else { @@ -118,9 +126,9 @@ static void push_swap_qsort_rec(t_stack *main, t_stack *tmp, return ; if (frame_length(main, main_frame) == 2) { - if (main->tag == STACK_A ? - main->elements[main->top] > main->elements[main->top - 1] - : main->elements[main->top] < main->elements[main->top - 1]) + if (not_a_ternary(main->tag == STACK_A, + main->elements[main->top] > main->elements[main->top - 1], + main->elements[main->top] < main->elements[main->top - 1])) stack_swap_print(main); return ; } @@ -140,7 +148,7 @@ static void push_swap_qsort_rec(t_stack *main, t_stack *tmp, ** wrapper for push_swap_qsort_rec */ -void push_swap_qsort(t_stack *a, t_stack *b) +void push_swap_qsort(t_stack *a, t_stack *b) { push_swap_qsort_rec(a, b, 0, 0); } -- cgit