title: Reverse Traversing singly linked list in C++
body: <p>Recently I have been asked this question on an interview. All I could do is traverse from 9 to 1 from a linked list starting from 0 to 9. Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  typedef struct node {                                                               
        int data;               // will store information
        node *next;             // the reference to the next node
  };  
  node *head;
  
  int printList(node *traverse) {
      if (traverse-&gt;next == NULL) {
          return -1;
      }
      traverse=traverse-&gt;next;
      printList(traverse);
  
      cout &lt;&lt; traverse-&gt;data &lt;&lt; endl;
      return 0;
  }
  
  int main() {
      node *temp = NULL;
      node *begin = NULL;      
      for (int i = 0; i &lt; 10; i++) {
          temp = new node;
          temp-&gt;data = i;
          if (begin == NULL) {
              begin = temp;
          }
          if (head != NULL) {
              head-&gt;next = temp;
          }
          head = temp;
          head-&gt;next = NULL;
      }
      head = begin;
      printList(head);
      return 0;
  }
  </code></pre>
  
  <p>1) How can I print 0(the first element) with the <code>printList()</code> recursive function?</p>
  
  <p>2) How can I replace <code>printList()</code> recursive function with while loop?</p>
  
  <p>3) If asked in an interview, does the <code>main()</code> function has proper node initialisation and insertation?</p>