-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_create_a.c
48 lines (44 loc) · 1.48 KB
/
ft_create_a.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_create_a.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlana <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/29 20:20:47 by dlana #+# #+# */
/* Updated: 2021/10/02 14:58:54 by dlana ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void ft_check_already_sorted_list(t_point *points)
{
if (points->a->numb > points->a->next->numb)
{
points->need_sort = 1;
}
}
void ft_create_a(t_point *points, int numb, int i)
{
int number;
t_list *tmp;
number = numb;
tmp = malloc(sizeof(t_list));
if (!tmp)
ft_error();
tmp->numb = number;
tmp->id_new = i;
if (points->a == 0)
{
tmp->prev = tmp;
tmp->next = tmp;
}
if (points->a != 0)
{
tmp->prev = points->a->prev;
points->a->prev->next = tmp;
tmp->next = points->a;
points->a->prev = tmp;
}
points->a = tmp;
ft_check_already_sorted_list(points);
}