yes,i know there is no faster way
and it's the basic way
but we have a 'list' parameter and we don't know what is shown by it.
But the original question was: How do I change this function to append to (the end of) a list.
As such, all you have to do is:
1) use a global tail and head pointer.
2) use this function:
Code:
void append( Node *n )
{
if( n )
{
if( listTail )
{
listTail->next = n;
n->prev = listTail;
}
listTail = n;
}
}
After all, if we're changing the function, why bother with that prototype? Actually, you could also do:
Code:
void append( int data )
{
Node *n = malloc( sizeof( Node ) );
n->data = data;
if( listTail )
{
listTail->next = n;
n->prev = listTail;
}
listTail = n;
}
Quzah.