Want to save binary tree to disk for “20 questions” game

后端 未结 8 2018

In short, I\'d like to learn/develop an elegant method to save a binary tree to disk (a general tree, not necessarily a BST). Here is the description of my problem:

I\'

8条回答
  •  一整个雨季
    2021-02-06 15:33

    A simple way to accomplish this is to traverse the tree outputting each element as you do so. Then to load the tree back, simply iterate through your list, inserting each element back into the tree. If your tree isn't self balancing, you may want to reorder the list in such a way that the final tree is reasonably balanced.

提交回复
热议问题