Note that there are some explanatory texts on larger screens.

plurals
  1. POLinked list with multiple parent and child nodes
    primarykey
    data
    text
    <p>I am trying to design a program that takes in data from a file, after which it gives numbering to unique data, linked list also contains parent and child lists.</p> <p>Data structure:</p> <pre><code> ____A / | B C | / \ E--&gt; F G | | | I J K </code></pre> <p>The nodes can have more than one next nodes (e.g. A and C), and can have more than one previous nodes.</p> <p>The text file contains the data like this, i'll get the data from file and <strong>turn them into linked list</strong>:</p> <pre><code> A B E I A C E F J A C G K </code></pre> <p><strong>My Question:</strong> Is it possible to create linked list with nodes with more than one next or more than one previous nodes, if so how would the struct look like?</p> <p><strong>What i have tried:</strong></p> <p>I made a struct which contains an array of 4 integers for parent and child.</p> <pre><code>struct abcd{ char data; int nodeid; int parent[4]; int child[4]; struct abcd *next; } </code></pre> <p>So the parent array holds node-id of <em>most previous</em> node (can be more than one since e.g. E (B &amp; C are pointing to it) --> (node-id - 1).</p> <p>Child array holds node-id of <em>instant next</em> node (node-id +1).</p> <p>There are no duplicate nodes for A or any other.</p> <p><strong>OUTPUT:</strong></p> <pre><code>1 : A &lt;-- 2 : B &lt;-- 1 3 E &lt;-- 2,5 4 : I &lt;-- 3 5 : C &lt;-- 1 6 : F &lt;-- 3 7 : J &lt;-- 6 8 : G &lt;-- 5 9 : K &lt;-- 8 </code></pre> <p>Hopefully its clear, please let me no how i should go about implementing it. Regards.</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.
 

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