-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_three_sort.c
37 lines (34 loc) · 1.41 KB
/
init_three_sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_three_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shaas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 17:19:10 by shaas #+# #+# */
/* Updated: 2022/03/09 17:19:40 by shaas ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void init_three_sort(t_list *stack_a, t_list *stack_b, unsigned int numnum)
{
unsigned int pushb;
unsigned int first;
unsigned int second;
unsigned int third;
pushb = numnum - 3;
while (pushb > 0)
{
push_b(stack_a, stack_b);
pushb--;
}
first = stack_a->head->rank;
second = stack_a->head->next->rank;
third = stack_a->tail->rank;
if (first < third && third < second)
swap_a(stack_a);
else if (second < first && first < third)
swap_a(stack_a);
else if (third < second && second < first)
swap_a(stack_a);
}