Traversal In linked list
<p>I am new to linked list..My simple code is to create linked list and insert nodes at the end and traverse it..<br>
 My problems are-<br>
 1)-Every time insert function is called,head pointer gets null<br>
2)-not working right while going in show function..</p>

<p>Please help..Thanks in advance    </p>

<pre><code>#include&lt;iostream&gt;
#include&lt;malloc.h&gt;
using namespace std;

struct linkedList
{
    int value;
    linkedList *next;
};
linkedList* head = NULL;
void insert(linkedList* head, int data)
{

    linkedList *ptr;
    linkedList *node;
    node = (linkedList*) malloc(sizeof(struct linkedList));
    node-&gt;value = data;
    node-&gt;next = NULL;
    if (head == NULL)
    {

        head = node;

    }
    else
    {
        ptr = head;
        while (ptr != NULL)
        {
            ptr = ptr-&gt;next;
        }
        ptr = node;
    }
}
void show(struct linkedList *head)
{

    struct linkedList *ptr;
    ptr = head;

    while (ptr != NULL)
    {
        cout &lt;&lt; ptr-&gt;value &lt;&lt; endl;
        ptr = ptr-&gt;next;
    }
}
int main()
{

    int size = 5;

    int array[size];
    for (int i = 0; i &lt; 5; i++)
    {
        cout &lt;&lt; "Enter value" &lt;&lt; endl;
        cin &gt;&gt; array[i];

        insert(head, array[i]);
    }

    show(head);

}
</code></pre>