예제 #1
0
 public void PrintInorderTraversal(BinaryTreeNode binaryTreeNode)
 {
     if (binaryTreeNode == null)
     {
         return;
     }
     PrintInorderTraversal(binaryTreeNode.GetBinaryTreeNodeLeft());
     Console.Write(binaryTreeNode.GetBinaryTreeNodeData() + " ");
     PrintInorderTraversal(binaryTreeNode.GetBinaryTreeNodeRight());
 }
 private static void _SerializeBinaryTree(BinaryTreeNode binaryTreeNode, StreamWriter streamWriter)
 {
     if (binaryTreeNode == null)
     {
         streamWriter.WriteLine("-1");
         return;
     }
     streamWriter.WriteLine(binaryTreeNode.GetBinaryTreeNodeData() + "");
     _SerializeBinaryTree(binaryTreeNode.GetBinaryTreeNodeLeft(), streamWriter);
     _SerializeBinaryTree(binaryTreeNode.GetBinaryTreeNodeRight(), streamWriter);
 }
        private static BinaryTreeNode _DeserializeBinaryTree(BinaryTreeNode binaryTreeNode, StreamReader streamReader)
        {
            String s = streamReader.ReadLine();

            if (s == "-1")
            {
                return(null);
            }

            binaryTreeNode = new BinaryTreeNode(int.Parse(s));
            binaryTreeNode.SetBinaryTreeNodeLeft(
                _DeserializeBinaryTree(binaryTreeNode.GetBinaryTreeNodeLeft(), streamReader));
            binaryTreeNode.SetBinaryTreeNodeRight(
                _DeserializeBinaryTree(binaryTreeNode.GetBinaryTreeNodeRight(), streamReader));
            return(binaryTreeNode);
        }