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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -