I'll assume you are trying to implement a Stack (given the pop() operation). I'm not entirely sure why you need a reference to firLink, but in a well implemented stack that shouldn't be problem....so We'll ignore that for now.
The pop should be independent of which Node you pass in (so you shouldn't have to set to firLink)....If this is the lastNode (ie forLink == NULL) then we set
-
tempNode = _node;
-
_node->bacLink->forLink=NULL;
-
free(tempNode);
-
otherwise, we move along forLink until we are at the last Node and do the same thing.
The thing here is that you can modify the list, but you can't update the callers pointer (although you could do by passing a pointer to a pointer)
The point is you can update the data Structure, but not the pointer.....
As long as the caller keeps some reference to firstNode (maybe instead of each Node referencing it), you can modify this structure quite easily.....
(I'm also wondering whether
-
n = listPop(new); //where new is a listNode obviously.
-
should read
-
n = listPop(&new); //where new is a listNode obviously.
-
{and good idea to avoid using new, but I know this was just for an example})