Creating single linked list in c++ : <p>I am a beginner in coding and i am creating a linked list(without using class concept), but this is not working, please help.</p>

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

struct node{
    int data;
    node *next;
};

void add(int n){
    node *head = NULL;
    node *temp = (node*)malloc(sizeof(node));
    temp-&gt;data = n;
    temp-&gt;next = head;
    head=temp;
}
void traverse(){
    node *temp1 = head;
    while(temp1!=NULL){
        cout&lt;&lt;temp1-&gt;data;
        temp1 = temp1-&gt;next;
    }
}
int main(){
    add(1);
    add(2);
    add(3);
    traverse();
    return 0;
}
</code></pre>
