title: Problem in adding a new node at the front of the linked list
body: <p>I'm trying to add a new node to the beginning of the linked list .So the newly added node becomes the new head of the Linked List and the previous head of the linked list becomes the second node.
  Here is my code:</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;iomanip&gt;
  
      class Node
      {
          public :
          int data ;
          Node * next ;
      } ;
  
      void printNodes(Node * node) ;
      void pushFront(Node * headReference, int newNode) ;
  
      int main()
      {
           Node * head = NULL,
           * second = NULL,
           * third = NULL ;
  
           head = new Node() ;
           second = new Node() ;
           third = new Node() ;
  
           head -&gt; data = 1 ;
           head -&gt; next = second ;
  
           second -&gt; data = 2 ;
           second -&gt; next = third ;
  
           third -&gt; data = 3 ;
           third -&gt; next = NULL ;
  
           pushFront(head, 4) ;
           printNodes(head) ;
  
           return 0 ;
     }
  
     //Printing the linked list nodes.
     void printNodes(Node * node)
     {
          int counter = 0 ;
  
          while(node != NULL)
          {
               ++ counter ;
               std::cout &lt;&lt; "Node " &lt;&lt; std::setfill('0')
                         &lt;&lt; std::setw(2)
                         &lt;&lt; counter
                         &lt;&lt; " --&gt; "
                         &lt;&lt; node -&gt; data
                         &lt;&lt; std::endl ;
  
               node = node -&gt; next ;
          }
  
          std::cout &lt;&lt; "Linked List finished" &lt;&lt; std::endl ;
     }
  
     //Inserting a new node on the front of the list.
     void pushFront(Node * headReference, int newData)
     {
          Node * newNode = new Node() ;
  
          newNode -&gt; data  = newData ;
  
          newNode -&gt; next = headReference ;
  
          headReference = newNode ;
     }
  </code></pre>
  
  <p>The output I expected is :</p>
  
  <p>Node 01 --> 4</p>
  
  <p>Node 02 --> 1</p>
  
  <p>Node 03 --> 2</p>
  
  <p>Node 04 --> 3</p>
  
  <p>Linked List finished</p>
  
  <p>The result I got is :</p>
  
  <p>Node 01 --> 1</p>
  
  <p>Node 02 --> 2</p>
  
  <p>Node 03 --> 3</p>
  
  <p>Linked List finished</p>