title: Converting a linked list to a circular list
body: <p>first time using this site and beginner in C++. I have a linked list built and am trying to convert it to a circular linked list but it's not going so well. Anyone will to give me their 2 cents as to where I am going wrong? Thanks. </p>
  
  <p>Edit: The problem is, after my attempt to connect the last node to the first, I display the list again and the first node seems to have been replaced with the last node.</p>
  
  <p>list before: 123456
  list after: 623456</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "SuitorNode.h"
  
  using namespace std;
  
  void getNumSuitors(int&amp; numberOfSuitors);
  void headInsert(SuitorNodePtr&amp; head, int value);
  
  int main()
  {
      SuitorNodePtr head, temp, remove;
      int numberOfSuitors;
  
      getNumSuitors(numberOfSuitors);
  
  
      head = new SuitorNode(numberOfSuitors);
  
      //Creates list of nodeswith the desired number of suitors
      for (int i = numberOfSuitors-1; i &gt; 0; --i)
      {
          headInsert(head, i);
      }
  
  
      // Iterate through the list and display each value
      temp = head;
      while (temp != NULL)
      {
          cout &lt;&lt; temp-&gt;getNum();
          temp = temp-&gt;getNext();
  
      }
  
      cout &lt;&lt;  endl;
  
  
      //get to last node, connect to first, delete head
      temp = head;
  
      while (temp-&gt;getNext() != NULL)
      {
          temp = temp-&gt;getNext();
      }
  
      //Attempt to create circular list
  
      temp-&gt;setNext(head-&gt;getNext());
      delete head;
  
  
  
      for (int i = 0; i &lt; numberOfSuitors; ++i)
      {
          cout &lt;&lt; temp-&gt;getNum();
          temp = temp-&gt;getNext();
      }
  
      cout &lt;&lt; endl;
  
      return 0;
  }
  
  void getNumSuitors(int&amp; numberOfSuitors)
  {
      cout &lt;&lt; "Please enter the number of suitors:";
      cin &gt;&gt; numberOfSuitors;
  
      do
      {
          if (numberOfSuitors &lt;= 0)
          {
              cout &lt;&lt; "Invalid number of suitors. Requires more than 1 suitor\n";
              cout &lt;&lt; "Please enter the number of suitors:";
              cin &gt;&gt; numberOfSuitors;
          }
          else if (numberOfSuitors == 1)
          {
              cout &lt;&lt; "Trivial number of suitors. Requires more than 1 suitor\n";
              cout &lt;&lt; "Please enter the number of suitors:";
              cin &gt;&gt; numberOfSuitors;
          }
          else
          {
              cout &lt;&lt; "You entered " &lt;&lt; numberOfSuitors &lt;&lt; " suitors.\n";
          }
      } while (numberOfSuitors &lt;= 1);
  }
  
  
  
  void headInsert(SuitorNodePtr&amp; head, int value)
  {
      SuitorNodePtr tempPtr;
      tempPtr = new SuitorNode(value);
      tempPtr-&gt;setNext(head);
      head = tempPtr;
  }
  
  
  class SuitorNode
  {
  public:
      SuitorNode();
      ~SuitorNode();
      SuitorNode(int initialnum);
      int getNum();
      SuitorNode* getNext();
      void setNext(SuitorNode *nextNode);
  
  
  private:
      SuitorNode *next;
      int num;
  };
  
  typedef SuitorNode* SuitorNodePtr;
  
  
  
  SuitorNode::SuitorNode() : num(0), next(NULL)
  {
      //deliberately empty
  }
  
  
  SuitorNode::~SuitorNode()
  {
  }
  
  
  SuitorNode::SuitorNode(int initialnum) : num(initialnum), next(NULL)
  {
      //deliberately empty
  }
  
  int SuitorNode::getNum()
  {
      return num;
  }
  
  SuitorNode* SuitorNode::getNext()
  {
      return next;
  }
  
  void SuitorNode::setNext(SuitorNode *nextNode)
  {
      next = nextNode;
  }
  </code></pre>