title: circular linked list (insert at beginning)
body: <p>This is my code. A circular linked list has two functions, one to insert at the beginning and the other to insert at end. When I run it, it works, but there is an error that it doesn't
  display the last node, i think because <code> head=p;</code> not <code>head-&gt;next=p;</code> but if I do <code>head-&gt;next=p;</code> it is a segmentation error
  How can I fix this fault?</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct node {
      int info;
      node* next;
  };
  
  node* head = NULL;
  
  void insert_b(int data) {
      node* p = new node; //create
      p-&gt;info = data; //fill
      if (head == NULL) {
          head=p;
          p-&gt;next = head;
          
      }
      else {
          p-&gt;next = head-&gt;next;
          head-&gt;next = p;
      }
  
  
  void traverse() {
      node* curr = NULL;
      for (curr = head-&gt;next; curr != head; curr = curr-&gt;next) {
          cout &lt;&lt; curr-&gt;info &lt;&lt; &quot;  &quot;;
      }
  }
  
  int main() {
      int data;
      cout &lt;&lt; &quot;enter data: &quot;;
      cin &gt;&gt; data;
      insert_b(7);
      insert_b(2);
      insert_b(1);
      traverse();
  
      return 0;
  }
  </code></pre>