title: Print out the circular linked list in C++?
body: <p>I want to print out a circular linked list. How would you print them out?</p>
  
  <p>This one is for regular linked list. And if I implement this for circular list, it loops for ever. Any idea to restrict and print out just one circle?</p>
  
  <pre><code>struct node* curr_node_1 = head;
  while ( curr_node_1 != nullptr )
  {
      cout &lt;&lt; curr_node_1-&gt;p_data &lt;&lt; ", ";
      curr_node_1 = curr_node_1-&gt;p_next;
  }
  </code></pre>
  
  <p>And my node struct is following</p>
  
  <pre><code> struct node
   {
      int            p_data;
      struct node*   p_next;
  
      node(node* head, int data)
      {
          p_next = head;
          p_data = data;
      }
  
      explicit node(int data)
      {
          p_next = nullptr;
          p_data = data;
      }
   };
  </code></pre>