2

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?

1

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I think you should use a more recent javadoc instead of 1.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.