You have a binary tree (not BST), serialize it in a stream and reconstruct the tree maintaining the format of the tree.
Sending 2 streams InOrder + PreOrder or InOrder + PostOrder is not an option.
Can anyone suggest some solution, using JAVA?
You have a binary tree (not BST), serialize it in a stream and reconstruct the tree maintaining the format of the tree.
Sending 2 streams InOrder + PreOrder or InOrder + PostOrder is not an option.
Can anyone suggest some solution, using JAVA?
If your data structure allows it, you could use Java Serialization API. If your tree objects (and all objects referenced from it) implement java.io.Serializable
, you could use the API serialize the whole structure into a stream and then deserialize it at some different place. (The linked page contains an example.) The serialization library handles dependencies between serialized objects, so that they are properly restored when deserailizing.
In addition to Petr's answer you might want to have a look here.
Be sure that the object that should be streamed implements the java.io.Serializable
interface.