#include <stdio.h>
#include <stdlib.h>

typedef struct list_t
{
    int value;
    struct list_t * next;
} list;

void insert(list **, int);
void print(list *);
void destroy(list *);

int main()
{
    list * mylist = NULL;

    insert(&mylist, 10);
    insert(&mylist, 20);

    print(mylist);
    destroy(mylist);
    return 0;
}

void insert(list ** head, int value)
{
    list * new_node = NULL;
    new_node = (list *)malloc(sizeof(list));

    new_node->value = value;
    new_node->next = NULL;

    if(*head == NULL)
    {
        *head = new_node;
    }
    else
    {
        list * cur = *head;
        while(cur->next != NULL)
        {
            cur = cur->next;
        }
        cur->next = new_node;
    }
}

void print(list * head)
{
    while(head != NULL)
    {
        printf("%d\t", head->value);
        head = head->next;
    }
}

void destroy(list * head)
{
    while(head != NULL)
    {
        list * tmp = head->next;
        free(head);
        head = tmp;
    }
}