For a binary tree, preorder traversal may be enough.
For example,
_30_ / \ 10 20 / / \ 50 45 35
The result is
30 10 50 # # # 20 45 # # 35 # #
Using a queue to deserialize it .
But a for multi-way tree, we could also use an array to serialize it, e.g.,
30 10 20 50 45 35
-1 0 0 1 2 2
时间: 2024-11-05 13:50:36