示例#1
0
        public static void Main(string[] args)
        {
            TreeNode root  = new TreeNode(1);
            TreeNode nodeA = new TreeNode(2);
            TreeNode nodeB = new TreeNode(3);
            TreeNode nodeC = new TreeNode(4);
            TreeNode nodeD = new TreeNode(5);
            TreeNode nodeE = new TreeNode(6);

            root.Left   = nodeA;
            root.Right  = nodeB;
            nodeA.Left  = nodeC;
            nodeC.Left  = nodeD;
            nodeC.Right = nodeE;

            Reverser reverser = new Reverser();
            TreeNode newRoot  = reverser.ReverseTree(root);

            Console.WriteLine(newRoot.Value + " " + newRoot.Left.Value + " " + newRoot.Right.Value);
            Console.WriteLine(newRoot.Right.Right.Value + " " + newRoot.Right.Right.Left.Value + " " + newRoot.Right.Right.Right.Value);
        }
		public static void Main (string[] args)
		{
			TreeNode root = new TreeNode (1);
			TreeNode nodeA = new TreeNode(2);
			TreeNode nodeB = new TreeNode (3);
			TreeNode nodeC = new TreeNode(4);
			TreeNode nodeD = new TreeNode (5);
			TreeNode nodeE = new TreeNode(6);

			root.Left = nodeA;
			root.Right = nodeB;
			nodeA.Left = nodeC;
			nodeC.Left = nodeD;
			nodeC.Right = nodeE;

			Reverser reverser = new Reverser ();
			TreeNode newRoot = reverser.ReverseTree (root);

			Console.WriteLine (newRoot.Value + " " + newRoot.Left.Value + " " + newRoot.Right.Value);
			Console.WriteLine (newRoot.Right.Right.Value + " " + newRoot.Right.Right.Left.Value + " " + newRoot.Right.Right.Right.Value);
		}