reverse link list using recursion
<p>I am trying to reverse a link list using recursion. I have written a function "reverse(node* ptr) for this
I am getting output as 40 40 20 while i expect output to be 40 , 20 , 10. 
below is the code posted. </p>

<pre><code>class list {
    //some code;

    void reverse()
    {
        node* temp = new node;
        temp =first;
        reverse(temp);
        temp =NULL;
        delete temp;
    }

    void reverse(node* ptr) {


        if(ptr-&gt;next != NULL)
        {
           ptr =ptr-&gt;next;
           reverse(ptr);
        }
        cout &lt;&lt; ptr-&gt;data &lt;&lt; endl;
    }
    // some code;
};

int main()
{
    list ll;
    ll.insert(18);
    ll.insert(20);
    ll.insert(40);
    ll.display();
    ll.reverse();
    return 0;
}
</code></pre>

<p>please suggest what I am doing wrong here.</p>

<p>Thanks</p>
