-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
74 lines (68 loc) · 1.9 KB
/
main.c
File metadata and controls
74 lines (68 loc) · 1.9 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kikiz <kikiz@student.42istanbul.com.tr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/25 03:24:21 by kikiz #+# #+# */
/* Updated: 2025/04/07 18:05:07 by kikiz ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void push_swap(t_stack **stack_a, t_stack **stack_b, int stack_size)
{
if (stack_size == 2 && !is_sorted(*stack_a))
ft_sa(stack_a, 1);
else if (stack_size == 3)
sort_three(stack_a);
else if (stack_size > 3 && !is_sorted(*stack_a))
sort_stack(stack_a, stack_b);
}
int is_space_null(char **argv)
{
int i;
int j;
int flg;
i = 0;
while (argv[++i])
{
if (argv[i][0] == '\0')
return (1);
j = 0;
flg = 1;
while (argv[i][j])
{
if (argv[i][j] == ' ')
j++;
else
{
flg = 0;
j++;
}
}
if (argv[i][j] == '\0' && flg == 1)
return (1);
}
return (flg);
}
int main(int argc, char **argv)
{
t_stack *stack_a;
t_stack *stack_b;
int stack_size;
if (argc < 2)
return (0);
if (is_space_null(argv))
{
write(2, "Error\n", 6);
return (-1);
}
get_stack_a(argc, argv, &stack_a, &stack_b);
stack_size = get_stack_size(stack_a);
index_stack(stack_a, stack_size);
push_swap(&stack_a, &stack_b, stack_size);
free_stack(&stack_a);
free_stack(&stack_b);
return (0);
}