home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!emory!swrinde!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!not-for-mail
- From: amusgrov@scotmhs.fred.org (Aj musgrove)
- Newsgroups: comp.lang.pascal
- Subject: Re: Returned mail: User unknown
- Message-ID: <4DHyXB1w165w@scotmhs.fred.org>
- Date: 25 Jan 93 17:17:46 GMT
- Article-I.D.: scotmhs.4DHyXB1w165w
- References: <9301220523.AA25652@acme.fred.org>
- Sender: daemon@cs.utexas.edu
- Organization: Scotlandville Magnet High School
- Lines: 74
- NNTP-Posting-Host: cs.utexas.edu
-
- >From acme.fred.org!MAILER-DAEMON Thu Jan 21 21:23:07 1993 remote from scotmhs
- Received: by scotmhs.fred.org (1.65/waf)
- via UUCP; Fri, 22 Jan 93 04:18:16 EST
- for amusgrov
- Received: by acme.fred.org (5.65/1.35)
- id AA25652; Thu, 21 Jan 93 21:23:07 -0800
- Date: Thu, 21 Jan 93 21:23:07 -0800
- From: acme.fred.org!MAILER-DAEMON (Mail Delivery Subsystem)
- Subject: Returned mail: User unknown
- Message-Id: <9301220523.AA25652@acme.fred.org>
- To: scotmhs!amusgrov
-
- ----- Transcript of session follows -----
- >>> RCPT To:<comp-lang-pascal@ucbvax.berkeley.edu>
- <<< 550 <comp-lang-pascal@ucbvax.berkeley.edu>... User unknown
- 550 comp-lang-pascal@ucbvax.berkeley.edu... User unknown
-
- ----- Unsent message follows -----
- Received: by acme.fred.org (5.65/1.35)
- id AA25650; Thu, 21 Jan 93 21:23:07 -0800
- Received: by scotmhs.fred.org (1.65/waf)
- via UUCP; Thu, 21 Jan 93 11:15:02 EST
- for comp-lang-pascal@ucbvax.berkeley.edu
- To: comp-lang-pascal@ucbvax.berkeley.edu
- Subject: Needed: A Recursive binary search function
- From: amusgrov@scotmhs.fred.org (Aj musgrove)
- Message-Id: <kTiqXB1w165w@scotmhs.fred.org>
- Date: Thu, 21 Jan 93 11:11:19 EST
- Organization: Scotlandville Magnet High School
-
- finocchiaroj@merrimack.edu writes:
-
- > I need the code for a recursive binary search function and if anyone has or
- > knows of one off hand I would really appreciate if you would mail me the
- > code for it.
- >
- > Thanks,
- > finocchiaroj@merrimack :)
-
-
- Ok, it'll be a mirical if this post makes it out of the system, but here
- is the code for the function that you want:
-
- First, the type declaration:
- TYPE
- st20 = string[20];
- nodeptr = ^node;
- node = RECORD
- data : st20;
- left, right : nodeptr;
- END;
-
- Now, the 'find' (search) procedure:
- PROCEDURE Find( Tree : nodeptr; VAR loc : nodeptr; tofind : st20 );
- BEGIN
- IF tree <> nil THEN
- BEGIN
- IF tofind = tree^.data THEN loc := tree
- ELSE
- if tofind < tree^.data THEN find(tree^.left,loc,tofind) ELSE
- find(tree^.right,loc,tofind);
- END;
- END;
-
- The original parameter 'loc' should be nil. Tofind is the search string,
- and the original Tree is the root of your tree. If you follow the logic
- of binary trees, then you will see that It decides 'higher' or 'lower'
- and goes that way, until it finds what it is looking for, or runs out of
- places to look.
-
- It will return a pointer to the proper node in 'loc', or 'loc = nil' if
- it isn't found.
-
- AJ
-