static void Main(string[] args) { var s = new Codec(); var tree = new TreeNode(1) { left = new TreeNode(2), right = new TreeNode(3) { left = new TreeNode(4), right = new TreeNode(5) } }; Console.WriteLine(s.serialize(tree)); var result = s.deserialize(s.serialize(tree)); }
public static void Main() { Codec c = new Codec(); TreeNode root = new TreeNode(1); TreeNode left = new TreeNode(2); TreeNode right = new TreeNode(3); root.left = left; left.right = right; var serialized = c.serialize(root); var retree = c.deserialize(serialized); }
public static void Main(string[] args) { var codec = new Codec(); var tree = new TreeNode(1) { left = new TreeNode(2), right = new TreeNode(3) { left = new TreeNode(4), right = new TreeNode(5) } }; Console.WriteLine(codec.serialize(tree)); var str = "[1,2,3,null,null,4,5]"; var head = codec.deserialize(str); Traverse(head); var str2 = "[]"; var head2 = codec.deserialize(str2); Traverse(head2); var str3 = "[1]"; var head3 = codec.deserialize(str3); Traverse(head3); var str4 = "[1,3,null,null,4]"; var head4 = codec.deserialize(str4); Traverse(head4); var str5 = "[1,2,null,3,null,4,null,5]"; var head5 = codec.deserialize(str5); Traverse(head5); }