invalid maps
This commit is contained in:
@@ -12,57 +12,51 @@
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
t_adjnode *lm_new_node(int dest)
|
||||
{
|
||||
t_adjnode *new;
|
||||
|
||||
if (!(new = (t_adjnode *)malloc(sizeof(t_adjnode))))
|
||||
return (NULL);
|
||||
new->dest = dest;
|
||||
new->next = NULL;
|
||||
return (new);
|
||||
t_adjlist *lm_new_node(int dest)
|
||||
{
|
||||
t_adjlist *newnode;
|
||||
|
||||
if (!(newnode = (t_adjlist *)malloc(sizeof(t_adjlist))))
|
||||
return (NULL);
|
||||
newnode->dest = dest;
|
||||
newnode->next = NULL;
|
||||
return (newnode);
|
||||
}
|
||||
|
||||
t_graph *lm_creategraph(int v)
|
||||
{
|
||||
t_graph *new_graph;
|
||||
int index;
|
||||
t_graph *newgraph;
|
||||
int index;
|
||||
|
||||
index = -1;
|
||||
if (!(new_graph = (t_graph *)malloc(sizeof(t_graph))))
|
||||
return (NULL);
|
||||
new_graph->vert = v;
|
||||
if (!(new_graph->array = (t_adjlist *)malloc(sizeof(t_adjlist) * v)))
|
||||
return (NULL);
|
||||
while (++index < v)
|
||||
new_graph->array[index].head = NULL;
|
||||
return (new_graph);
|
||||
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_ext_conn(t_graph *graph, t_lmdata *data,
|
||||
char *raw, t_syntax *synt)
|
||||
{
|
||||
char **tab;
|
||||
|
||||
if (synt->gr_status == 5)
|
||||
{
|
||||
graph = lm_creategraph(data->nb_nodes);
|
||||
synt->gr_status = 1;
|
||||
}
|
||||
tab = ft_strsplit(raw, '-');
|
||||
if (tab != NULL)
|
||||
lm_add_edge(graph, lm_find_index(data, tab[0]), lm_find_index(data, tab[1]));
|
||||
}
|
||||
|
||||
//function to add the edges and create a proper adjacency list
|
||||
void lm_add_edge(t_graph *graph, int src, int dest)
|
||||
{
|
||||
t_adjnode *newnode;
|
||||
t_adjlist *newnode;
|
||||
|
||||
newnode = lm_new_node(dest);
|
||||
newnode->next = graph->array[src].head;
|
||||
graph->array[src].head = newnode;
|
||||
newnode = lm_new_node(src);
|
||||
newnode->next = graph->array[dest].head;
|
||||
graph->array[dest].head = 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;
|
||||
}
|
Reference in New Issue
Block a user