Attempted insert node leads to infinite linked list : <p>I am trying to insert a node into a linked list after it finds a name in the list.
My problem is that when i print out the linked list it prints the nodes up to and including the node containing the name but then outputs infinitely the node I inserted. Any help would be greatly appreciated. Thanks!</p>

<p>(some extra information),(the pointer student is pointing to a dynamically created node already). :)</p>

<pre><code>bool StudentLinkedList::insertStudentAfter(StudentNode* student, string _name)
{
StudentNode* curr = headP;
StudentNode* prev = headP;
while (curr != NULL)
{
    if (curr-&gt;getName() == _name)
    {


        StudentNode* dummy = curr -&gt; getnext();

        curr-&gt;setNext(student);
        prev = prev-&gt;getnext();

        curr=curr -&gt;getnext();
        curr-&gt;setNext(dummy);

        prev = curr;
        curr = curr-&gt;getnext();


       length++;
        return true;
    }
    prev = curr;
    curr = curr-&gt;getnext();
}
return false;
</code></pre>

<p>}</p>
