Code:
struct node *addNodeToFront( struct node *list, int value )
{
struct node *newNode = malloc (sizeof(*newNode));
if (newNode != NULL)
{
newNode -> data = value;
newNode -> nextNode = list;
}
return newNode;
}
struct node *addNodeToBack( struct node *list, int value )
{
struct node *newNode = malloc (sizeof(*newNode));
if (newNode != NULL)
{
newNode -> data = value;
newNode -> nextNode = NULL;
if ( list == NULL )
{
list = newNode;
}
else
{
struct node *tail = head;
while ( tail->next != NULL ) tail = tail->next;
tail->next = newNode;
}
return list;
}
int main()
{
struct node *list = NULL;
list = addNodeToFront(list, 2 );
list = addNodeToBack(list, 3 );
return 0;
}