Using C++, how can I move nodes backwards in a singly linked list?
<pre><code>    void currentbac()
   {

       if (current == first)
       cout &lt;&lt; "This is the beginning of the list." &lt;&lt; endl;
     else
      {
        list *previous;
        previous = first;
        while (previous-&gt;next != current)
          {
              previous = previous-&gt;next;
          }
        current = previous;
      }
   }
</code></pre>

<p>This is the code I put for moving the "current" pointer backwards.
I 've initialized both current and first to null at the start of my code.</p>

<p>What I really want is to move the node through my list of nodes forward or backward.and then I want to insert a node whereever neccessary.
I know there are doubly linked lists but if someone can post the code for doubly linked list moving thats fine too.
But I wanted to know if you can move using a single linked list.</p>

<p>Also</p>

<pre><code>void addmiddle()

{

    if (current==NULL)
    {
    cout &lt;&lt; "Current is invalid" &lt;&lt; endl;
    return;
    }
    if ( current-&gt;next==NULL)
       addending();
    else
     {
         list *newlist;
         newlist=new list;
         cout &lt;&lt; "Enter your name:" ;
         cin &gt;&gt; newlist-&gt;name;
         cout &lt;&lt; "Enter your age:" ;
         cin &gt;&gt; newlist-&gt;age;
         cout &lt;&lt; "Enter your height:" ;
         cin &gt;&gt; newlist-&gt;height;
         newlist-&gt;next=current-&gt;next;
         current-&gt;next=newlist;
     }
}
</code></pre>

<p>^ this is my code for adding a node in the middle of the list.I wanted to know how it works cos apparently im not able to move "Current"backwards.</p>
