c++ - In a linked list, in what order are nodes removed by the destructor? -


this question has answer here:

in linked list, in order nodes removed destructor?

does go first last or last first?

either order possible -- way inspect specific implementation you're using.

in general, singly-linked list, expect first-to-last ordering because it's easier implement , bit more efficient:

linkedlist::~linkedlist() {     node *node = mhead;     while (node) {         node *next = node->mnext;         delete node;         node = next;     } } 

versus last-to-first ordering, singly-linked list require sort of recursion:

void deletelist(node *node) {     if (node == 0) {        return;     }     deletelist(node->mnext);     delete node;     return; } linkedlist::~linkedlist() {    deletelist(mhead); } 

so again -- way sure @ linked list implementation.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -