-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.c
92 lines (82 loc) · 2.05 KB
/
utils.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
91
92
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcerchi <mcerchi@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/26 14:50:06 by mcerchi #+# #+# */
/* Updated: 2022/02/26 14:50:08 by mcerchi ### ########.fr */
/* */
/* ************************************************************************** */
#include "./libft/libft.h"
#include "push_swap.h"
void ft_lst_delete(t_list **stack)
{
t_list *tmp;
if (*stack == NULL)
return ;
tmp = *stack;
while (*stack != NULL)
{
tmp = (*stack)->next;
free (*stack);
*stack = tmp;
}
}
void ft_lstcheck(t_list *stack_a, int check)
{
while (stack_a->next != NULL)
{
if (stack_a->content == check)
ft_display_exit();
stack_a = stack_a->next;
}
return ;
}
void ft_lst_order(t_list **stack_a)
{
t_list *tmp;
t_list *tmp2;
tmp = *stack_a;
tmp2 = tmp->next;
while (tmp2 != NULL)
{
if (tmp->content > tmp2->content)
return ;
tmp = tmp->next;
tmp2 = tmp2->next;
}
exit(0);
}
void ft_lst_inverted(t_list **stack_a)
{
t_list *tmp;
t_list *tmp2;
tmp = *stack_a;
tmp2 = tmp->next;
while (tmp2 != NULL)
{
if (tmp->content < tmp2->content)
return ;
tmp = tmp->next;
tmp2 = tmp2->next;
}
ft_sa(stack_a);
return ;
}
void ft_write_lst(t_list **stack_a, int argc, char **argv, int i)
{
t_list *tmp;
tmp = NULL;
while (i < argc)
{
tmp = ft_lstnew(ft_atoi(argv[i]));
ft_lstadd_back(stack_a, tmp);
ft_lstcheck(*stack_a, tmp->content);
i++;
}
ft_lst_order(stack_a);
ft_lst_inverted(stack_a);
tmp = NULL;
}