Program title: Binary Trees Demo Written by: (I got it from ZUG disc 14, and Ray Penley did the work) (Buddenberg) Date written: November 1981 Last edited: June 1982 rab Pascal compiler: Pascal/Z vers 4.0, Ithaca Intersystems, Inc. Summary: Maintain a sorted list in a binary tree Bibliography: GROGONO, P.: Programming in PASCAL, Addison-Wesley Publishing Co., Reading, MA. TENENBAUM, A. and AUGENSTEIN, M.: Data Structures Using Pascal, Prentice-Hall, Englewood Cliffs, N.J. 07632 WIRTH, N.: Algorithms + Data Structures = Programs, Prentice-Hall, Englewood Cliffs, N.J. 07632 Notes to latest edition. by Rex A Buddenberg 1. Program broken up into modules for separate compilation. My editor gets cantankerous with files larger than its buffer, and the "disc" module took a lot of troubleshooting to get it working properly. The modules are named: BTREE the main program DISC procedures for reading and writing the leaves to disc file ORDER three procedures, PRE-, POST-, and IN-ORDER for traversing the tree. DELETE the delete procedures for removing a record from the tree and relinking what is left. MENU utility routines including MENU and HELP. 2. Added options 4,5, and 8 to the menu. Store and Fetch are the significant "improvements". They allow writing the tree out to disc and later recovering it. Thus the data contents can be preserved. The user can now customize the insert and list routines to make a practical program. 3. A couple glitches. When loading a data file from disc, you will get a bell and a note that that record already exists on the tree. No harm done, but a GOTO is needed in the FETCH procedure to jump out of the loop on End-Of-File. Having some problem with the DELETE feature. Some flexibility here in finding records on, say, the first 10 characters rather than the whole record might make things easier. 4. Things remaining. Several further developments can be implemented, but most of the hard work is done. Some ideas: - add some data checking to the insert routine. To do this, I would suggest making a separately compiled procedure, rather than leaving it in the main program block. - add an option to search through the file looking for some field other than the key. Speed sacrifices are certainly entailed, but the flexibility would be enhanced. As records are stored in-memory rather than on disc, the speed of search still should be fairly quick. - expand the HELP command usefulness. Adding code to allow calling from several different procedures would allow the operator to check up on instructions at opportunity rather than solely from the master menu. - allow sorted listing to D)isk as well as C)onsole and P)rinter. Note that this should not be used for data storage, but for output storage. To be efficient, Btrees should be balanced. Data placed on the tree in order will result in a lopsided tree - essentially a linked list. Things will work ok, but the efficiency and speed of the tree structure is lost. - some reformatting of the P)rinter routine would allow for printing on either labels, index or rolodex card stock. If the blank "2nd address line" still is omitted, you gotta put in another linefeed somewhere to compensate. - the insertion SORT program on Disc 16 can easily be adapted to sort the data files created by this tree program into order by a different field. You lose a bit of interactiveness, but if you are making cross reference lists, that's not a problem. - enhance the DELETE routine to find the to-be-deleted record, display it and ask if that is the record to go. This could also be further enhanced to allow changes in data fields(so long as the key is not changed) and replacement on the tree. .