Ejemplo n.º 1
0
        public void NoLCA()
        {
            BinaryTree <string> tree = getExampleTree();
            Node <string>       k    = Q03 <string> .BfsFind(tree, "K")?[0];

            Assert.NotNull(k);

            Node <string> lcaNode = Q03 <string> .FindLCA(tree, k, tree.Root);

            Assert.Null(lcaNode);
        }
Ejemplo n.º 2
0
        public void Test01()
        {
            BinaryTree <string> tree = getExampleTree();
            Node <string>       d    = Q03 <string> .BfsFind(tree, "D")?[0];

            Node <string> n = Q03 <string> .BfsFind(tree, "N")?[0];

            Assert.NotNull(d);
            Assert.NotNull(n);

            Node <string> lcaNode = Q03 <string> .FindLCA(tree, d, n);

            Assert.Equal(tree.Root, lcaNode);
        }
Ejemplo n.º 3
0
        public void Test02()
        {
            BinaryTree <string> tree = getExampleTree();
            Node <string>       c    = Q03 <string> .BfsFind(tree, "C")?[0];

            Node <string> l = Q03 <string> .BfsFind(tree, "L")?[0];

            Node <string> p = Q03 <string> .BfsFind(tree, "P")?[0];

            Assert.NotNull(c);
            Assert.NotNull(l);
            Assert.NotNull(p);
            Assert.Equal(l, c.Left.Left);
            Assert.Equal(p, c.Right);

            Node <string> lcaNode = Q03 <string> .FindLCA(tree, l, p);

            Assert.Equal(c, lcaNode);
            Assert.Equal("C", lcaNode.Value);
        }
Ejemplo n.º 4
0
        public void Example()
        {
            BinaryTree <string> tree = getExampleTree();
            Node <string>       k    = Q03 <string> .BfsFind(tree, "K")?[0];

            Node <string> m = Q03 <string> .BfsFind(tree, "M")?[0];

            Node <string> n = Q03 <string> .BfsFind(tree, "N")?[0];

            Assert.NotNull(k);
            Assert.NotNull(m);
            Assert.NotNull(n);
            Assert.Equal(m, k.Left.Right);
            Assert.Equal(n, k.Right);

            Node <string> lcaNode = Q03 <string> .FindLCA(tree, m, n);

            Assert.Equal(k, lcaNode);
            Assert.Equal("K", lcaNode.Value);
        }