Appending or prepending lists is easy. I really prefer double linked lists, but for now I'll just use single.
First, make a function that returns the last node in a list. I'll do an easy version:
Code:
struct node * GetLast( struct node * n )
{
struct node *e, *x;
for( e = n; e && e->next; e = e->next );
return e;
}
Assume that the pointers point to the first node in a list.
Prepend ListA to ListB:
Code:
struct node *ListA, *ListB;
struct node *temp;
temp = GetLast( ListA );
if( temp )
temp->next = ListB;
Now the last node in ListA points to the first in ListB.
Assume that the pointers point to the first node in a list.
Append ListA to ListB:
Code:
struct node *ListA, *ListB;
struct node *temp;
temp = GetLast( ListB );
if( temp )
ListB->next = ListA;
Pretty simple stuff.
Quzah.