I have a pseudo graph conformed by adjacency lists, where tree is an array of "lista_t"
typedef struct nodo {
int value;
struct nodo *next;
} nodo_t;
typedef struct {
nodo_t *primero;
nodo_t *ultimo;
int len;
} lista_t;
Well and my problem is that the function add_edge()
is not always executed, it inserts correctly, the function executes correctly close to 100000000
times.
But for example the array in the position [722606]
, (that is the 722606va list created at the beginning and with a single node) its first 103 inserts are done correctly, but at the moment of adding the value 106098 to the list add_edge()
does not insert the element, then the 105th insertion is 75695, and it does not insert it either, until it reaches its last insertion 558624, which adds it correctly.
For example, the number of entries in the position [722606]
is 108, meanwhile the length of the list is missing values and its parameter list-> len is equal to 106. (It generates segmentation faults)
scanf("%d\n",N);
nodo_t *aux = (nodo_t*)malloc(sizeof(nodo_t));
aux->value= N;
aux->next = NULL;
for (i=0;i<N;i++)
add_fedge(&tree[i],aux);
scanf("%d\n",&M);
for (i=0;i<M;i++){
scanf("%d %d\n", &aux1 , &aux2 );
add_edge(&tree[aux1],aux2);
add_edge(&tree[aux2],aux1);
}
I do the corresponding malloc
scanf("%d\n",&N);
lista_t* tree = (lista_t*)malloc(N*sizeof(lista_t));
And my functions are (they are in another file)
extern void add_edge(lista_t *l,int x){
nodo_t *aux = malloc(sizeof(nodo_t));
aux->value = x;
aux->next = l->primero;
l->primero = aux;
l->len++;
}
extern void add_fedge(lista_t *l,nodo_t *aux){
l->primero = aux;
l->ultimo = aux;
l->len = 1;
}
- C ++ lists are somewhat slower
- The idea is not to make checks or count to remove the length in case of error since the arrangement is 1 million lists
approximately, where each list has an average of 1500 elements
(I took out the calculations)