Exemplo n.º 1
0
        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="node"></param>
        /// <param name="direction"></param>
        public void AddNode(ChainTree <T> node, int direction)
        {
            if (Root == null)
            {
                Root = node;
            }

            switch (direction)
            {
            case 0:
                if (Root.Left == null)
                {
                    Root.Left = node;
                }
                break;

            case 1:
                if (Root.Left == null)
                {
                    Root.Left = node;
                }
                break;
            }

            AddNode(node, 0);
            AddNode(node, 1);
        }
Exemplo n.º 2
0
        private static void Algorithm()
        {
            Algorithm          a    = new Algorithm();
            ChainTree <string> root = new ChainTree <string>();

            root.left           = new ChainTree <string>();
            root.data           = "根节点";
            root.left.data      = "左子树";
            root.left.left      = new ChainTree <string>();
            root.left.left.data = "左子树的左子树";
            root.right          = new ChainTree <string>();
            root.right.data     = "右子树";
            //a.TreeDRT(root);//先序遍历
            //a.TreeLRT(root);//中序遍历
            a.TreeLRD(root);//后序遍历
            Console.Read();
        }