-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_swap.c
61 lines (55 loc) · 1.74 KB
/
push_swap.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhlim <zhlim@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/25 13:40:20 by zhlim #+# #+# */
/* Updated: 2023/08/10 23:47:01 by zhlim ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void print_stack(t_list *stack)
{
t_content *content;
while (stack)
{
content = stack->content;
ft_printf("%d ", content->number);
stack = stack->next;
}
ft_printf("\n");
}
void do_sort(t_list **stack_a, t_list **stack_b, int size)
{
if (size == 2)
{
while (!check_sorted(*stack_a))
single_rotate(stack_a, "ra\n");
}
else if (size <= 3)
sort_3(stack_a);
else
sort_advance(stack_a, stack_b, size);
}
int main(int ac, char **av)
{
t_list *stack_a;
t_list *stack_b;
char **args;
int size;
int to_free;
to_free = 0;
args = validate_args(ac, av, &to_free);
stack_a = build_stack_a(args);
if (to_free)
free_args(args);
stack_b = NULL;
check_dup(stack_a);
size = get_index((ft_lstlast(stack_a))->content) + 1;
if (!check_sorted(stack_a))
do_sort(&stack_a, &stack_b, size);
ft_lstclear(&stack_a, destroy_content);
return (0);
}