Writing a LinkedList destructor?

后端 未结 6 1885
我在风中等你
我在风中等你 2020-12-30 05:36

Is this a valid LinkedList destructor? I\'m still sort of confused by them.

I want to make sure I\'m understanding this correctly.

 LinkedList::~Link         


        
6条回答
  •  猫巷女王i
    2020-12-30 06:10

    Tested OK

    Destructor for class List

    List::~List()
    {
        Node *n = this->front, *current = NULL; //initialization part
    
        while(n)                               //start cleanup of nodes of the list
        {
            current = n;
            n=n->next;
            delete(current);
        }
    
        front = end = NULL;
    }
    

提交回复
热议问题