IT WORKS !

functionning ./lem_in that can read maps and display ants path
still need to clean leaks
still need remove debug info
This commit is contained in:
Tanguy MAZE
2019-04-09 19:09:29 +02:00
parent 434b629055
commit 3b893147e5
11 changed files with 364 additions and 235 deletions

View File

@@ -6,57 +6,28 @@
/* By: mndhlovu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/29 07:17:06 by mndhlovu #+# #+# */
/* Updated: 2019/03/29 07:17:26 by mndhlovu ### ########.fr */
/* Updated: 2019/04/09 18:18:59 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
t_adjlist *lm_new_node(int dest)
int lm_adj_parser(t_lmdata *lmdata, t_holder *holder)
{
t_adjlist *newnode;
t_temp *data;
if (!(newnode = (t_adjlist *)malloc(sizeof(t_adjlist))))
return (NULL);
newnode->dest = dest;
newnode->next = NULL;
return (newnode);
if (holder != NULL)
{
data = holder->data;
if (data != NULL)
{
while (data)
{
lst_indadd_link(lmdata, data->src_ind, data->dest_ind);
data = data->next;
}
return (1);
}
}
return (0);
}
t_graph *lm_creategraph(int v)
{
t_graph *newgraph;
int index;
index = -1;
if (!(newgraph = (t_graph *)malloc(sizeof(t_graph))))
return (NULL);
newgraph->v = v;
//create an array of adjacency list. size of array will be v
if (!(newgraph->array = (t_adj *)malloc(sizeof(t_adj) * v)))
return (NULL);
while (++index < v)
newgraph->array[
index].head = NULL;
return (newgraph);;
}
void lm_add_edge(t_graph *graph, int src, int dest)
{
t_adjlist *newnode;
/*
* Add an edge from src to dest. A new node is added to the adjacency list of
* src. The node is added at the beginning
*/
newnode = lm_new_node(dest);
newnode->next = graph->array[src].head;
graph->array[src].head = newnode;
/*
* Since graph is undirected, add an edge from dest to src also
*/
newnode = lm_new_node(src);
newnode->next = graph->array[dest].head;
graph->array[dest].head = newnode;
}