Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like you are using a queue (remove from the front, add to the back) kind of data structure to store unprocessed nodes. As nodes are inserted into your output data structure they are dropped from the queue. If a node cannot be added to the output (because its 'parent' has not been moved to the output data structure yet) it is re-queued. Eventually the queue should become empty unless there are nodes where the 'parent' does not exist (orphans).</p> <p>I imagine your algorithim looks something like</p> <pre><code> Do While not QueueEmpty() node = Dequeue() ' Remove from the front if not AddNodeToTree(node) then Queue(node) 'add to the back end </code></pre> <p>Where <code>AddNodeToTree</code> is a function that takes a node, successfully adds it to the output and returns <code>True</code>. Otherwise it returns <code>False</code> causing the node to recycle.</p> <p>The only thing you should have to do is add a sentinal node to the back of the queue and a flag to indicate that at least one node was consumed from the queue during one complete cycle through it. The above algorithm becomes:</p> <pre><code>set NodeProcessed to False Queue(SentinalNode) ' marker to identify cycle through queue Do while not QueueEmpty() node = Dequeue() if isSentinalNode(node) then if NodeProcessed then Queue(node) set NodeProcessed to False else ' Queue contains only orphans or is empty end end if AddNodeToTree(node) then set NodeProcessed to True else Queue(node) end end </code></pre> <p>The <code>SentinalNode</code> is a marker that you use to detect looping through the queue.</p> <p>Your output data structure looks like it contains a 'forest' of trees. That is, it contains several distinct trees. If there is any possibility that a given node may be shared among two or more trees, the above algorithm will not work properly. If a node may appear in at most one tree in the 'forest' then the above should be fine.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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