Q. Write down an algorithm to insert a node in the beginning of the linked list.
Ans:
/* structure containing a link part and link part data part */
struct node
{
int data ;
struct node * link ;
} ;
/* Following adds a new node at the beginning of the linked list */
void addatbeg ( struct node **q, int num )
{
struct node *temp ;
/* add new node */
temp = malloc ( sizeof ( struct node ) ) ;
temp -> data = num ;
temp -> link = *q ;
*q = temp ;
}