Looks okay. If the list is empty, you add a node at the front. If the list isn't empty, you add a node ad the end. I don't think createnode() is good though because it doesn't return an error status or you don't check for it. That leaves you with ignoring the error of not being able to create a node, or just closing the program. Both are bad. I'd write it something like this:
Code:
struct node *createnode( int data, struct node *prev, struct node *next ) {
struct node *new = malloc( sizeof *new );
if ( new ) {
new->data = data;
new->prev = prev;
new->next = next;
}
return new;
}
Then you can use it like this:
Code:
int insertNode( struct node **head, int data)
{
struct node *tempnode, *tempnode1;
if( *head == NULL )
{
*head = createnode( data, NULL, NULL );
if ( *head == NULL ) {
return 0;
}
}
else
{
tempnode = *head;
while( empnode->next != NULL )
tempnode = tempnode->next;
tempnode1 = createnode( data, tempnode, NULL );
if ( tempnode1 == NULL ) {
return 0;
}
tempnode->next = tempnode1;
}
return 1;
}