Ciao a tutti.
Sono ormai da ore che provo a cercare l'errore in questo codice ma non riesco a venirne a capo. Spero qualcuno riesca a farmi luce. In pratica non mi modifica firstVertex facendolo rimanere sempre NULL. Come mai? Ve lo posto:
Graziecodice:typedef struct node *edgeInfo; //Informazione su un arco della rete typedef struct node { int secondVertex; int edgeCost; edgeInfo nextAdj; } edge; ..... firstVertex = NULL; srand((unsigned) time(&t)); //genera un seme casuale basato sul tempo per rand() a riga 71 for(i=0; i<numNodi; i++) { power = rand() % 12; // genera un valore casuale da 0 a 11 if (power == 0) i--; // elimino le istanze pari a 0 else { if (power == 11) power = 50; // massima distanza printf("%d: %d \n", i, power); pnt1 = creaStruct(i, power); aux = scorriLista(firstVertex, i); assegnaAux(aux, pnt1) } } ...... edgeInfo creaStruct(int sV, int eC) { edgeInfo pnt; pnt = (edgeInfo) malloc (sizeof(edge)); pnt->secondVertex = sV; pnt->edgeCost = eC; pnt->nextAdj = NULL; return pnt; } edgeInfo scorriLista(edgeInfo pnt, int i) { edgeInfo aux; aux = pnt; if (aux == NULL) return aux; while(aux->nextAdj != NULL) aux = aux->nextAdj; return aux; } void assegnaAux(edgeInfo aux, edgeInfo pnt) { if (aux==NULL) aux = pnt; else aux->nextAdj = pnt; }![]()

Rispondi quotando