-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_process_queue.c
94 lines (85 loc) · 2.07 KB
/
ft_process_queue.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
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_process_queue.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dzui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/08/11 14:17:19 by dzui #+# #+# */
/* Updated: 2017/08/11 14:17:20 by dzui ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
void ft_add_path(t_lem *lem, t_path **path, int *vis)
{
if (*(path) == NULL)
*(path) = ft_create_path(lem, vis);
else
ft_append_path(path, lem, vis);
ft_remove_last_visited(lem, vis);
lem->index -= 1;
lem->counter++;
}
int ft_get_last_in_queue(int *queue, int size)
{
int i;
i = 0;
if (queue[size - 1] != -1)
return (queue[size - 1]);
while (i < size - 1)
{
if (queue[i + 1] == -1)
break ;
i++;
}
return (queue[i]);
}
void ft_assign_queue(t_lem *lem, int *queue, int *visited, int size)
{
int i;
int j;
int k;
i = 0;
while (i < size)
{
queue[i] = -1;
i++;
}
j = 0;
k = 0;
i = ft_get_last_visited(lem, visited);
while (j < lem->size)
{
if (lem->adj_matrix[i][j] == 1 && !ft_was_visited(lem, j, visited))
{
queue[k] = j;
k++;
}
j++;
}
}
void ft_remove_queue_elem(t_lem *lem, int *queue, int size, int elem)
{
int i;
i = 0;
while (i < size)
{
if (queue[i] == elem)
{
queue[i] = -1;
break ;
}
i++;
}
while (i < lem->size - 1)
{
queue[i] = queue[i + 1];
i++;
}
}
int ft_rooms_connection(t_lem *lem, int room_1, int room_2)
{
if ((lem->adj_matrix[room_1][room_2] == 1) || (room_1 == room_2))
return (1);
return (0);
}