public static void CalcDistance(string[,] inputMatrix) { int size = inputMatrix.GetLength(0); int[,] matrix = ParseMatrix(inputMatrix); Queue <HelpNode> queue = new Queue <HelpNode>(new[] { startNode }); while (queue.Count > 0) { HelpNode currNode = queue.Dequeue(); int row = currNode.Row; int col = currNode.Col; List <HelpNode> children = new List <HelpNode>() { new HelpNode(row + 1, col), new HelpNode(row - 1, col), new HelpNode(row, col + 1), new HelpNode(row, col - 1) }; foreach (var child in children) { if (inBounds(child.Row, child.Col, size) && matrix[child.Row, child.Col] == 0) { matrix[child.Row, child.Col] = matrix[row, col] + 1; queue.Enqueue(new HelpNode(child.Row, child.Col)); } } } PrintMatrix(matrix); }
/// <summary> /// Tests the two nodes by comparing the names and the children. /// </summary> /// <param name="nodeA">The first node.</param> /// <param name="nodeB">The second node.</param> private void TestNodes(HelpNode nodeA, HelpNode nodeB) { Assert.AreEqual(nodeA.Name, nodeB.Name, "Node name values do not match"); Assert.AreEqual(nodeA.Children.Count, nodeB.Children.Count, "Child counts do not match"); for (int i = 0; i < nodeA.Children.Count; i++) { TestNodes(nodeA.Children[i], nodeA.Children[i]); } }
private void CreateDynamicActions(HelpNode node) { string action = node.Anchor; if (!DynamicActions.ContainsKey(action)) { DynamicActions[action] = new HelpDynamicAction(); } foreach (HelpNode helpNode in node.Contents) { CreateDynamicActions(helpNode); } }
public HelpContents() { root = new HelpNode("Help Contents", null, null); currentNode = root; }
public void Add(HelpNode node) { Contents.Add(node); }
public HelpContents GoToRoot() { currentNode = root; return this; }
public HelpContents AddSection(string name, string anchor) { currentNode = new HelpNode(name, anchor, null); root.Add(currentNode); return this; }