Hi there,
I'm becoming increasingly confused trying to implement an array of pointers, that themselves point to nodes in a linked list. Basically my problem is that I need to sort through an existing linked list per element, over all other elements (which works fine) based on a particular criterion, and per element create a new linked list that any element in the original linked list that satisfies the criterion is added to. I have chosen to have these new linked lists in an array i.e. an array of linked lists, but am running into trouble owing to my lack of understanding both data types!
As I say, the sorting itself works fine its just the creating of an array of pointers that each point to a new linked list.
The basics of my main() function are as follows:
---------------------------------------------------------------------------------------
node *head = NULL; //pointer to initial list of particles
node* list[100]; //array of 100 pointers to nodes
// For each particle loop over all other particles
// Use the radius constraint to define neighbour lists
search_particle_add(&head, &list[particleno], radius);
----------------------------------------------------------------------------------------
The search_particle_add() function takes the following arguments:
int search_particle_add(node **thisptr, node *list[], double rad)
And within the search_particle_add function there is another function that adds the new particle (assuming it satisfies the criterion) to a new linked list (i.e. one of those contained in the array list[]). That function is called in search_particle_add() by:
add_p(&list[i], &iterate->p);
And it is defined by:
node* add_p(node **ptr, struct particle *value)
My problem is either that the array of pointers isn't being created properly, or that particles aren't being added to the various linked lists properly, as when I try and display the contents of the various linked lists in the array list[], there's nothing there, even though quite a few relevant particles were definitely found by the sorting algorithm and the add_p() function was called on them.
Help! I've no doubt used wrong referencing or dereferencing somewhere, but can't figure out where!
Any advice would be appreciated.
Alex