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

后端 未结 8 2014

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:34

    I would store the tree like this:

    
    node data
    [
      yes child]
    [
      no child]
    
    

    where the child nodes are just recursive instances of the above. The bits in [] are optional and the four identifiers are just constants/enum values.

提交回复
热议问题