Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Linked and doubly-linked lists are a specific variety of <strong>directed graphs</strong> which can be optimized into the <code>head/tail</code>, <code>data/next/prev</code> structure you're familiar with. Since you're broadening its capabilities, you lose that specificity, and want to go back to the generic directed graph structure and work from there.</p> <p>A directed graph is most easily described with an adjacency list: <img src="https://i.stack.imgur.com/0pOWE.gif" alt="image of graphs with adjacency lists"></p> <p>You can implement that with as a list of lists, or an array of lists, or a jagged array, or however you like. Now, on the right, I've drawn a doubly-linked list in directed graph form. Since the <code>next</code> pointers are different from <code>prev</code> pointers, your adjacency list needs to keep those separate. So it will actually be a list of dual lists:</p> <pre><code>typedef struct _BPNode { // "Back-Pointing Node" void *data; struct _BPNode *nexts[]; struct _BPNode *prevs[]; } Node; typedef struct _BPGraph { // "Back-Pointing Graph" Node **allNodes; } BPGraph; </code></pre> <p>Or something like that. Disclaimer: I didn't test this in a compiler. And just in case, <a href="http://unixwiz.net/techtips/reading-cdecl.html" rel="nofollow noreferrer">here's a guide on how to read some of the declarations in there</a>.</p> <p>Alternatively, you can create two directed graphs, one running forward, and one running backward. However, that would take more memory than this "back-pointing" graph. It would also run slower (more cpu cache misses), would be less intuitive, and would be more troublesome to free memory for.</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