// A sample program illustrating how to make a linked list
// There are lots of different ways of organizing your code
// - this example shows one way, not necessarily the best way.
// Cameron Hayne, November 2003

#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;

struct Node
{
    int val1;
    int val2;
    Node *next;
};

// file-scope variable for the head of the list:
static Node *head = 0;

int get_data()
{
    // for the purpose of this example
    // we just get random numbers as "data"

    return rand();
}

Node *create_new_node(int value1, int value2)
{
    Node *ptr = new Node;
    ptr->val1 = value1;
    ptr->val2 = value2;
    ptr->next = 0;
    return ptr;
}

void add_node_to_list(Node *node)
{
    // we put the node at the beginning of the list
    // since that is the simplest

    node->next = head;
    head = node;
}

void print_list()
{
    Node *ptr = head;

    while (ptr != 0)
    {
        cout << "Node: " << ptr->val1 << " " << ptr->val2 << endl;

        ptr = ptr->next;
    }
}

int main()
{
    int num_nodes = 5;

    for (int i = 0; i < num_nodes; i++)
    {
        int value1 = get_data();
        int value2 = get_data();
        Node *ptr = create_new_node(value1, value2);
        add_node_to_list(ptr);
    }

    print_list();
    return 0;
}


