-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_swap.c
52 lines (47 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hbaddrul <hbaddrul@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/26 11:17:50 by hbaddrul #+# #+# */
/* Updated: 2021/11/24 20:09:01 by hbaddrul ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "push_swap.h"
#include "libft/libft.h"
static void ps_free(char **strs)
{
int i;
i = 0;
while (strs[i])
free(strs[i++]);
free(strs);
}
int main(int argc, char **argv)
{
int len;
char **strs;
t_list *stack;
if (argc > 1)
{
strs = 0;
len = split_argv(&strs, argv + 1, " ");
if (!len || !is_valid(strs))
{
ps_free(strs);
ft_putendl_fd("Error", 2);
return (1);
}
stack = 0;
while (len--)
ft_lstadd_front(&stack, ft_lstnew(strs[len]));
if (!is_sorted(stack))
sort(&stack);
ft_lstclear(&stack, free);
free(strs);
}
return (0);
}