C++ array of linkedlist segmentation fault -


i trying fix method takes function takes root of linked list , number of vertices in graph , organizes linked list array of linked list based on first vertex of edge struct, example, in struct node edge has firvertex = 1, sndvertex = 2, , weight = 2, sorted first element of array. , node edge has firvertex = 1 appended onto previous one, , etc. have fixed many times still giving segmentation fault when running.

thanks tips, appreciate it. unfortunately, cannot leave code since school assignment.

the variable arraylist if declared local array. therefore is destroyed @ end of function , shouldn't returned. should allocate dynamically new:

edge** arraylist = new edge *[numbervertices]; 

by way compiler (if correctly configured) should warn you. here g++ -wall does:

bli.cpp: in function ‘edge** _()’: bli.cpp:5:9: warning: address of local variable ‘arraylist’ returned [-wreturn-local-addr]   edge* arraylist[500]; 

also looks suspicious me:

for (int i=0; i<numbervertices; i++) { //initializes array null    arraylist[numbervertices]=null; } 

you mean:

   arraylist[i]=null; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -