code_junkie

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

Nov 12th, 2011
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. void encodeState(OutputStream out,Node n) {
  2. if(n==null) {
  3. out.write("[null]");
  4. } else {
  5. out.write("{");
  6. out.write(n.nodeDetails());
  7. encodeState(out, n.yesNode());
  8. encodeState(out, n.noNode());
  9. out.write("}");
  10. }
  11. }
  12.  
  13. F
  14.  
  15. F
  16. B
  17.  
  18. F
  19. B G
  20.  
  21. F
  22. B G
  23. A
  24.  
  25. 1,2,3,"Does it have wings?"
  26. 2,0,0,"a bird"
  27. 3,4,0,"Does it purr?"
  28. 4,0,0,"a cat"
  29.  
  30. <node identifier>
  31. node data
  32. [<yes child identfier>
  33. yes child]
  34. [<no child identifier>
  35. no child]
  36. <end of node identifier>
  37.  
  38. <parent>,<relation>,<child>
  39.  
  40. "Is it Red", "yes", "does it have wings"
  41. "Is it Red", "no" , "does it swim"
  42.  
  43. [0x1111111 "Is It Red" => [ 'yes' => 0xF752347 , 'no' => 0xFF6F664 ],
  44. 0xF752347 "does it have wings" => [ 'yes' => 0xFFFFFFF , 'no' => 0x2222222 ],
  45. 0xFF6F664 "does it swim" => [ 'yes' => "I Dont KNOW :( " , ... etc etc ]
Add Comment
Please, Sign In to add comment