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