Note that there are some explanatory texts on larger screens.

plurals
  1. PODeep copy and deconstructor sentinel linked list using Nodes
    text
    copied!<p>I am currently making a linked List program using Nodes(not that i know of any other way) and I have come upon a problem about creating a deep copy and getting rid of all my Nodes and Sentinels with my ~List(). Deleting the Nodes is not a problem, but the sentinels are since the first one is not assigned a index value.</p> <pre><code>List::~List() { for(size_t i=0; i&lt;size; i++) { _setCurrentIndex(i); if(current &amp;&amp; curent-&gt;next == NULL) { Node *temp = current-&gt;next; delete temp; delete current; } else { Node *old = current; current = current-&gt;next; delete old; } } } List::List(const List &amp; orig) { for(size_t i=0; i&lt;size; i++) { if(i==0) { Node *copyFront = new Node; //the first sentinel copyFront-&gt;data = orig.front-&gt;data; //front is defined in private in list.h copyFront-&gt;prev = NULL; // it is defined as a Node (same for rear) } else if(0&lt;=i &amp;&amp; i&lt;size) //put in i&lt;size b/c 0&lt;=i would always be true { _setCurrentIndex(i) //sets what current is and currentIndex which pts to diff Nodes Node *copy = new Node; copy-&gt;data = current-&gt;data; copy-&gt;next = current-&gt;next; current = current-&gt;next; } else if(i+1 == size) { Node *copyRear = new Node; //making the last sentinel, but it has to be copyRear-&gt;data = orig.rear-&gt;data; //after data Node copyRear-&gt;next = NULL; } } } </code></pre> <p>I am seeking advice and comments on this code on how to proceed next or what to change if something is dreadfully wrong!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload