protected bool RemoveNodeRecursively(NodePath path, NodeContainer currentNode) { currentNode = (currentNode != null ? currentNode : this); string key = path.Dequeue(); if (currentNode.Nodes.ContainsKey(key)) { if (path.Path.Count <= 0) return currentNode.Nodes.Remove(key); else RemoveNodeRecursively(path, currentNode.Nodes[key]); } return false; }
protected void AddNodeRecursively(NodePath pathToGoal, Node node, NodeContainer mother) { mother = (mother != null ? mother : this); string key = pathToGoal.Dequeue(); if (pathToGoal.Path.Count > 0) { if (!mother.Nodes.ContainsKey(key)) mother.Nodes.Add(key, new Node(key)); Node newNode = mother.Nodes[key]; AddNodeRecursively(pathToGoal, node, newNode); return; } if (!mother.Nodes.ContainsKey(key)) mother.Nodes.Add(key, node); else mother.Nodes[key] = node; }