Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Suppose <code>node1-&gt;next == node2 &amp;&amp; node2-&gt;prev == node1</code>. Now let's trace:</p> <pre><code>if(node1-&gt;next!=NULL) { node1-&gt;next-&gt;prev=node2; } </code></pre> <p>Now <code>node2-&gt;prev</code> points to <code>node2</code> itself!</p> <pre><code>if(node2-&gt;prev!=NULL) { node2-&gt;prev-&gt;next=node1; } </code></pre> <p>Now <code>node2-&gt;next</code> points to <code>node1</code>, which is ok for now.</p> <p>Recall that <code>node1-&gt;next</code> still points to <code>node2</code>, and <code>node2-&gt;next</code> points to <code>node1</code>.</p> <pre><code>tmp=node1-&gt;next; // == node2 node1-&gt;next=node2-&gt;next; // == node1 (!) node2-&gt;next=tmp; // == node2 </code></pre> <p>So we have <code>node1-&gt;next</code> pointing to <code>node1</code>, and <code>node2-&gt;next</code> to <code>node2</code>. Clearly wrong.</p> <p>Recall that node2->prev points to <code>node2</code>, although <code>node1-&gt;prev</code> is correct.</p> <pre><code>tmp=node1-&gt;prev; // correct node1-&gt;prev=node2-&gt;prev; // == node2 node2-&gt;prev=tmp; // correct </code></pre> <p>So <code>node1-&gt;prev</code> points to <code>node2</code>, which is correct.</p> <p>But <code>node1-&gt;next</code> and <code>node2-&gt;next</code> are still wrong!</p> <hr> <p>How to solve this? It's not a one-liner to solve, as there are a couple special cases.</p> <p>Maybe detect the special case I described and have separate code for it (and don't forget about that other special case).</p> <p>Writing that code is left as an exercise to the reader ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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