title: Sort a list where predecessor and successor define the sort
body: <p>I need to sort a list of LineItems where in each LineItem there is a predecessor and successor defined.</p>
  
  <pre><code>LineItem{
     public int Id {get;set;}
     public int? PredecessorId {get;set;}
     public int? SuccessorId {get;set;}
  }
  </code></pre>
  
  <p>The first LineItem will have no PredecessorId and the last LineItem  will not have a SuccessorId.</p>
  
  <p>I thought I could just implement IComparable but for 2 only items its not possible calculate the sort in this case.</p>
  
  <p>How would I sort a list <code>List&lt;LineItem&gt;</code>?</p>
  
  <blockquote>
    <p>Edit</p>
  </blockquote>
  
  <p>Here is a sample</p>
  
  <pre><code> List&lt;LineItem&gt; lineItems = new List&lt;LineItem&gt;{
      new LineItem{ Id = 1, PredecessorId = 2,        SuccessorId = 103},
      new LineItem{ Id = 2, PredecessorId = null,     SuccessorId = 1},
      new LineItem{ Id = 103, PredecessorId = 1,      SuccessorId = 5},
      new LineItem{ Id = 4, PredecessorId = 5,        SuccessorId = null},
      new LineItem{ Id = 5, PredecessorId = 103,      SuccessorId = 4},
  
  
  };
  </code></pre>
  
  <p>The expected sort would be:</p>
  
  <p>2,1,103,5,4</p>