private void AddUnsortedNodes(SortedTreeNode <IdType, DataType> root) { // Add nodes without preferences foreach (IdType id in NodesToSort.Keys) { if (NodesToSort.TryGetValue(id, out SortedTreeNode <IdType, DataType> node)) { if (node.IsRoot) { continue; } if (node.IsLinked) { continue; } if (!node.HasOrdering) { root.SetLeftChild(node); continue; } else if (node.Dependencies.Count == 0) { bool noPreferences = true; foreach (IdType before in node.LoadBefore) { if (NodesToSort.ContainsKey(before)) { noPreferences = false; break; } } foreach (IdType after in node.LoadAfter) { if (NodesToSort.ContainsKey(after)) { noPreferences = false; break; } } if (noPreferences) { root.SetRightChild(node); continue; } } } } }
public void SetLeftChild(SortedTreeNode <IdType, DataType> node) { if (ReferenceEquals(node, this)) { return; } if (LeftChildNode == null) { LeftChildNode = node; node.Parent = this; } else { LeftChildNode.SetRightChild(node); } }