void add ( struct node **q, int num )
{
struct node *temp ;
/* add new node */
temp = ( struct node * ) malloc ( sizeof ( struct node ) ) ;
temp -> data = num ;
temp -> link = *q ;
*q = temp ;
}
This function is meant for adding a new item at the beginning of the list.
My doubt is that in most of the books the functions functions involving linked lists use pointer to the node structure rather that instance of the struct itself.
void add( struct node *q, int num )
{
struct node temp ;
temp.data = num ;
temp.link = q ;
q = &temp ;
}
Is there a reason the 1st form of the function is preferred or both methods are equally good?