示例#1
0
        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))));
        }
示例#2
0
        public ActionResult BFS()
        {
            var fullPath = HttpContext.Server.MapPath("~/Search");

            var traversedPaths = TraverseTree.BFS(fullPath);

            ViewBag.Paths = traversedPaths.ToString();
            return(View());
        }
示例#3
0
        public ActionResult DFS()
        {
            var startFolder    = HttpContext.Server.MapPath("~/Search");
            var traversedPaths = new StringBuilder();

            TraverseTree.DFS(startFolder, traversedPaths);

            ViewBag.Paths = traversedPaths.ToString();
            return(View());
        }