-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_swap.c
90 lines (81 loc) · 2.08 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zessadqu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/26 10:09:04 by zessadqu #+# #+# */
/* Updated: 2022/06/05 16:05:16 by zessadqu ### ########.fr */
/* */
/* ************************************************************************** */
#include "check_header.h"
void push(long long value, t_nums **a)
{
t_nums *tmp;
tmp = malloc(sizeof(t_nums));
tmp->num = value;
tmp->next = (*a);
tmp->prev = NULL;
if ((*a) != NULL)
(*a)->prev = tmp;
(*a) = tmp;
}
void great_list(int argc, char **argv, t_nums **a, int flag)
{
t_nums *tmp;
int i;
tmp = *a;
i = 1;
argc--;
while (argc)
{
push(ft_atoi_digit_confirm(argv[argc], a), a);
duplicate_check(*a, ft_atoi_digit_confirm(argv[argc], a), a);
argc--;
}
if (flag == 0)
{
push(ft_atoi_digit_confirm(argv[argc], a), a);
duplicate_check(*a, ft_atoi_digit_confirm(argv[argc], a), a);
}
}
void printlist(t_nums **a)
{
t_nums *c;
c = malloc(sizeof (t_nums));
if (!c)
return ;
c = *a;
while (c)
{
printf("%ld \n", c->num);
c = c->next;
}
}
int main(int argc, char **argv)
{
t_nums *a;
t_nums *b;
int i;
i = 0;
a = NULL;
if (argc == 2)
{
argv = ft_split(argv[1], ' ', &argc);
great_list(argc, argv, &a, 0);
argc++;
}
else
great_list(argc, argv, &a, 1);
b = NULL;
if (argc == 2)
return (0);
if (a == NULL || check_sort(a) == 1)
return (0);
if (argc >= 2 && argc < 7)
i += one_to_five(&a, &b, argc);
if (argc >= 7 && argc <= 501)
sort_med(&a, &b);
return (0);
}