Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   dealloc linked list (http://www.programmingforums.org/showthread.php?t=11929)

n00b Nov 18th, 2006 5:48 AM

dealloc linked list
 
this function deallocates a linked list. but it deallocates everything, including the head of the list.
how can i make it deallocate everything besides the head?

:

void deallocate()
{
        tstudent *current=list->next;
        tstudent *previous=list;
        while(current)
        {
                delete previous;// deallocation of list elements including head
                previous=current;
                current=current->next;
        }
        delete previous;
        return NULL;
};


Polyphemus_ Nov 18th, 2006 6:54 AM

Well, point 'previous' to list->next and 'current' to the node after that one.


All times are GMT -5. The time now is 1:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC