doubly linked lists insertion
Hey guys please correct me if im wrong but does all the code inside the if(*head ==NULL) its just initialize each to a safe state then creating a head node in our list.
Then if the head node is already created create prev and next pointers then create a new node with prev and next pointers to that as well.
Code:
void insertNode( struct node **head, int data)
{
struct node *tempnode, *tempnode1;
if( *head == NULL )
{
*head = createnode();
(*head)->next = NULL;
(*head)->prev = NULL;
(*head)->data = data;
}
else
{
tempnode = *head;
while( empnode->next != NULL )
tempnode = tempnode->next;
tempnode1 = createnode();
tempnode1->prev = tempnode;
tempnode1->next = NULL;
tempnode1->data = data;
tempnode->next = tempnode1;
}
}