title: Print function isn't working properly- Linked list
body: <p>I am new to the data structures and I was trying to write a code which add nodes to the beginning of the linked list. After every time user enters a new node, the program is supposed to display an updates linked list, but my program is only displaying the current entered node.</p>
  
  <p>The code is as follows: -</p>
  
  <pre><code>#include&lt;iostream.h&gt;
  #include&lt;conio.h&gt;
  struct Node
  {
    int data;
    Node* next;
  };
  struct Node* head;
  
  void Insert(int x) 
  {
    Node* temp=new Node();
    temp-&gt;data=x;
    temp-&gt;next=NULL;
    head=temp;
  }
  
  void Print()
  {
    struct Node* temp=head;
    cout&lt;&lt;"List is: ";
    while(temp!=NULL)
    {
      cout&lt;&lt;temp-&gt;data;
      temp=temp-&gt;next;
    }
    cout&lt;&lt;"\n";
  }  
  
  void main()
  {
    head=NULL;
    clrscr();
    cout&lt;&lt;"How many numbers?\n";
    int n,x,i;
    cin&gt;&gt;n;
    for(i=0; i&lt;n; i++) 
    {
      cout&lt;&lt;"Enter the number \n";
      cin&gt;&gt;x;
      Insert(x);
      Print();
    }
    getch(); 
  }
  </code></pre>