Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!usc!ucsd!ucsdhub!hp-sdd!hplabs!hpfcso!bigelow From: bigelow@hpfcso.HP.COM (Jim Bigelow) Newsgroups: comp.lang.pascal Subject: Re: [William Sweetman: help - binary search tree] Message-ID: <9110006@hpfcso.HP.COM> Date: 1 Dec 89 16:14:46 GMT References: <21597@adm.BRL.MIL> Organization: Hewlett-Packard, Fort Collins, CO, USA Lines: 25 I suggest that you look at the algorithms and programs in "Algorithms + Data Structurs = Programs" by N. Wirth. Chapter 4, Section 4.4 is titled "Tree Structures" and subsection 4.4.10 is "Optimal Search Trees." From the same book, Page 204, I've paraphrased the following search routine: procedure search(x:integer; var p:ref); begin if p = nil then begin { x not in tree, insert or inform user as you wish} end else if x < p^.key then search(x,p^.left) else if x > p^.key then search*x,p^.right) else p^.count := p^.count + 1 end {search}; You'll have to modify the defintion and uses of "ref" which is a pointer to a tree node. Best Regards, Jim Bigelow S300 Pascal Hewlett Packard.