home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6759 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.3 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  2. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Saving/Reading BinaryTrees.
  5. Message-ID: <dmurdoch.290.722207951@mast.queensu.ca>
  6. Date: 19 Nov 92 21:19:11 GMT
  7. References: <1egndqINNl2u@usenet.INS.CWRU.Edu>
  8. Sender: news@knot.ccs.queensu.ca (Netnews control)
  9. Organization: Queen's University
  10. Lines: 19
  11.  
  12. In article <1egndqINNl2u@usenet.INS.CWRU.Edu> br707@cleveland.Freenet.Edu (Mike L. Melamed) writes:
  13. >
  14. >Does anyone know how to save and then restore a binary tree from a disk?
  15.  
  16. You don't say what kind of Pascal you're using, but if it's one with objects 
  17. in it, it's very easy.  You'll have two kinds of nodes:  those that branch, 
  18. and those that contain data (or point to data).  To write a branching node 
  19. to disk, just write each of its branches.  To write a leaf node to disk, 
  20. just write the data.
  21.  
  22. To restore, let the OOP system determine what it sees in the file, and call 
  23. the appropriate loader.  If your branch loader gets called, it loads two 
  24. branches; if your leaf loader gets called, it just loads the data.
  25.  
  26. Reading and writing mixed structures is one place where OOP coding really 
  27. shines.
  28.  
  29. Duncan Murdoch
  30. dmurdoch@mast.queensu.ca
  31.