So here is the main method I have to work with:
Code:
int main(void) {
// a reference to the head of our list
node *head = NULL;
node ** list = &head;
// the nodes we will put in our list
node a = {6,NULL};
node b = {8,NULL};
node c = {4,NULL};
node d = {10,NULL};
node e = {2,NULL};
// build the list
append(list, &a);
append(list, &b);
prepend(list, &c);
append(list, &d);
prepend(list, &e);
// print the list
print(list);
// test the find function
int value;
for (value = 1; value <= 10; value++) {
node * found = find(list, value);
if (found == NULL)
printf("Node %d not found...\n", value);
else
printf("Found node %d!\n", found->content);
}
// test delete function
delete(list, 4);
delete(list, 8);
print(list);
return 0; }
What is going on here?:
Code:
node *head = NULL;
node ** list = &head;
A node called head is created and then another node which is called list is assigned the value in head? Is this redundant or does it serve a dual purpose I dont see? Why is the second node called list? Isn't it just a node and not a list? Aren't lists made up of nodes? How do I work with a pointer to just one node? In Java I would use two nodes like:
Code:
node *pFirstNode = NULL;
node *pLastNode = NULL;
Sorry that was a lot of questions... but im still new to C.