-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.c
69 lines (59 loc) · 1.95 KB
/
linked_list.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* linked_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbutt <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/12 13:59:01 by mbutt #+# #+# */
/* Updated: 2019/05/22 19:10:14 by mbutt ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Creating a linked list structure called new_node and allocating memory to it
*/
t_tetro *create(void *struct_tetro)
{
t_tetro *new_node;
new_node = (t_tetro *)malloc(sizeof(t_tetro));
if (new_node == NULL)
{
ft_exit();
}
new_node->struct_tetro = struct_tetro;
new_node->struct_c = 'A';
new_node->next = NULL;
return (new_node);
}
/*
** Creating a structure that appends new pieces to the existing structure
*/
t_tetro *append(t_tetro *head, void *struct_tetro)
{
t_tetro *cursor;
t_tetro *new_node;
cursor = head;
while (cursor->next != NULL)
cursor = cursor->next;
new_node = create(struct_tetro);
cursor->next = new_node;
return (head);
}
/*
** Taking coordinates of the shifted pieces that are currentlyin a 2D-array,
** and storing them in a linked list structure
*/
t_tetro *coord_to_struct(int **shifted_coordinates, int tetro_count)
{
t_tetro *pointer_2;
int i;
i = 1;
pointer_2 = create(shifted_coordinates[0]);
while (i < tetro_count)
{
pointer_2 = append(pointer_2, shifted_coordinates[i]);
i++;
}
return (pointer_2);
}