1. Mark Heath
  2. GraphPad

Commits

Mark Heath  committed 59f0bd0

added a sort method so a child cannot be behind a parent

  • Participants
  • Parent commits bae3775
  • Branches default

Comments (0)

Files changed (1)

File GraphPad/Logic/Graph.cs

View file
             return longest;
         }
 
+        public void Sort()
+        {
+            for (int index = 0; index < nodes.Count; index++)
+            {
+                Node n = nodes[index];
+                foreach (var c in n.Children)
+                {
+                    int childIndex = nodes.IndexOf(c);
+                    if (childIndex < index)
+                    {
+                        nodes.RemoveAt(index);
+                        nodes.Insert(childIndex, n);
+                        index = childIndex;
+                        break;
+                    }
+                }
+            }
+        }
+
         public Node FindNearestCommonAncestor(Node first, Node second)
         {
             var firstAncestors = first.FindLongestDistanceToAllAncestors();