title: Convert number sequence to Parent/Child hierarchy
body: <p>I'm loading a CSV file into my program which is passed from our legacy ERP System. The CSV contains <a href="https://en.wikipedia.org/wiki/Bill_of_materials" rel="nofollow">multi-level bill of materials (BOM)</a> data, that I will ultimately need to strip down and send each unique BOM off for processing. Currently, I'm struggling as record does not contain a parentID, instead relying on the order of the record to define any sort of parent/child relationship. 
  The only thing I have to go on is the Level and SubLevel are laid out in a set sequence</p>
  
  <ul>
  <li>Level 0 is the root and can contain 1 or more Level1</li>
  <li>Level 1 is the child of 0 and could contain 0 or more Level2</li>
  <li>Level 2 is the child of 1 and could contain 0 or more Level1</li>
  <li>etc...</li>
  </ul>
  
  <p>This is an example of the data which I've abbreviated for simplicity:</p>
  
  <pre><code>+---------------------------------+  
  ¦ UniquePartID ¦ Level ¦ SubLevel ¦  
  ¦--------------+-------+----------¦  
  ¦ 05468        ¦ 0     ¦ 0        ¦  
  ¦ 12420        ¦ 1     ¦ 1        ¦  
  ¦ 08186        ¦ 2     ¦ 1        ¦  
  ¦ 03926        ¦ 3     ¦ 1        ¦  
  ¦ 93650        ¦ 2     ¦ 2        ¦  
  ¦ 07642        ¦ 3     ¦ 1        ¦  
  ¦ 16569        ¦ 2     ¦ 3        ¦  
  ¦ 49397        ¦ 1     ¦ 2        ¦  
  ¦ 93093        ¦ 1     ¦ 3        ¦  
  ¦ 36250        ¦ 2     ¦ 1        ¦  
  +---------------------------------+  
  </code></pre>
  
  <p>And displayed hierarchically, this is how it would look:</p>
  
  <pre><code>                            0
              ------------------------
              |           |         | 
              1           1         1 
          ----------              ----
          |    |   |              |   
          2    2   2              2   
          -    -
          |    |
          3    3
  </code></pre>
  
  <p>I have loaded the CSV data into a class representation, but cannot figure an way to reliably identify a parent child relationship using the Level/Sublevel and the order of the file as my reference</p>
  
  <p>Does anyone have any advice I could use?            </p>