I'm creating an a* algorithm implementation using two double linked lists.
p_node is the node being copied. ppDest is the tail node and ppDestlist_h is the head node.
I'm not entirely sure about my double pointers and I might just be making a schoolboy error here. I only learnt about their use yesterday, and have converted my code to use it instead of returning pointers to the nodes.
Code:
int addtolist(p_node *node, p_node **ppDest, p_node *ppDestlist_h)
{
if(( node == NULL ))
{
printf("Node pointer is null!\n");
return 1;
}
/*edit* /
ppDest = &(*ppDestlist_h);
/*double pointers here are used to keep going forward until null is hit*/
/* if null is hit immediately then copy the node right away*/
while(*ppDest != NULL)
{ ppDest = &(*ppDest)->next;}
memcpy(&(*ppDest), &node, sizeof(p_node));
printf("node inside func: %d Current: \n", (*ppDest)->x);
/*now I set the next value of the node to NULL*/
(*ppDest)->next = NULL;
return;
}
This seems like it should work, but doesnt want to.
has anyone got any pointers? (ouch that was bad)
thanks,
-Simo