aaaaaaand it's done !

algorithm finished and normed
more testing might be needed
This commit is contained in:
Tanguy MAZE
2019-04-03 17:20:29 +02:00
parent 15669b7402
commit ea0eda89d0
5 changed files with 92 additions and 152 deletions

View File

@@ -6,26 +6,12 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/27 14:41:49 by tmaze #+# #+# */
/* Updated: 2019/04/01 17:52:57 by tmaze ### ########.fr */
/* Updated: 2019/04/03 17:19:07 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
static void bfs_print(t_bfs *tab, int nb_nodes)
{
int i;
i = 0;
ft_printf("===== bfs print =====\n");
while (i < nb_nodes)
{
ft_printf("index: %d\nparent: %d\nvisited: %d\nqueue: %d\n\n", i
, tab[i].parent, tab[i].visited != 0, tab[i].queue);
i++;
}
}
static void bfs_addtoqueue(t_bfs *tab, int node, int nb_nodes)
{
int i;
@@ -43,13 +29,26 @@ static void bfs_addtoqueue(t_bfs *tab, int node, int nb_nodes)
static void bfs_checkadj(t_lmdata *data, t_bfs *tab, int i)
{
t_ind *it;
char used;
it = data->adj[tab[i].queue];
used = 0;
while (it != NULL)
{
if (tab[it->index].visited == 0 && it->weight == 2)
used = 1;
if (tab[it->index].visited == 0 && it->weight == 2)
break ;
it = it->next;
}
it = data->adj[tab[i].queue];
while (it != NULL)
{
if (tab[it->index].visited == 0 && it->weight > 0)
if (tab[it->index].visited == 0 && ((!used && it->weight > 0)
|| (used && it->weight == 2)))
bfs_addtoqueue(tab, it->index, data->nb_nodes);
if (tab[it->index].visited == 0 && it->weight > 0)
if (tab[it->index].visited == 0 && ((!used && it->weight > 0)
|| (used && it->weight == 2)))
tab[it->index].parent = tab[i].queue;
it = it->next;
}
@@ -69,7 +68,7 @@ static void bfs_init(t_bfs *tab, t_lmdata *data)
}
}
void bfs(t_lmdata *data, t_bfs *tab, int start_ind, int end_ind)
void bfs(t_lmdata *data, t_bfs *tab, int start_ind, int end_ind)
{
int i;