public void traverseTreeTest() { var t = new TraverseTree(); var tree = @"{ ""value"": 1, ""left"": { ""value"": 2, ""left"": null, ""right"": { ""value"": 3, ""left"": null, ""right"": null } }, ""right"": { ""value"": 4, ""left"": { ""value"": 5, ""left"": null, ""right"": null }, ""right"": null } }"; var expected = new[] { 1, 2, 4, 3, 5 }; Assert.IsTrue(expected.SequenceEqual(t.traverseTree(JsonConvert.DeserializeObject <TraverseTree.Tree <int> >(tree)))); tree = @""; expected = new int[0]; Assert.IsTrue(expected.SequenceEqual(t.traverseTree(JsonConvert.DeserializeObject <TraverseTree.Tree <int> >(tree)))); tree = @"{ ""value"": 2, ""left"": { ""value"": 1, ""left"": null, ""right"": { ""value"": 0, ""left"": null, ""right"": null } }, ""right"": null }"; expected = new[] { 2, 1, 0 }; Assert.IsTrue(expected.SequenceEqual(t.traverseTree(JsonConvert.DeserializeObject <TraverseTree.Tree <int> >(tree)))); tree = @"{ ""value"": 15, ""left"": { ""value"": 15, ""left"": null, ""right"": null }, ""right"": null }"; expected = new[] { 15, 15 }; Assert.IsTrue(expected.SequenceEqual(t.traverseTree(JsonConvert.DeserializeObject <TraverseTree.Tree <int> >(tree)))); }
public ActionResult BFS() { var fullPath = HttpContext.Server.MapPath("~/Search"); var traversedPaths = TraverseTree.BFS(fullPath); ViewBag.Paths = traversedPaths.ToString(); return(View()); }
public ActionResult DFS() { var startFolder = HttpContext.Server.MapPath("~/Search"); var traversedPaths = new StringBuilder(); TraverseTree.DFS(startFolder, traversedPaths); ViewBag.Paths = traversedPaths.ToString(); return(View()); }