home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / pascal / 8540 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  2.9 KB

  1. Path: sparky!uunet!ogicse!emory!swrinde!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!not-for-mail
  2. From: amusgrov@scotmhs.fred.org (Aj musgrove)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Returned mail: User unknown
  5. Message-ID: <4DHyXB1w165w@scotmhs.fred.org>
  6. Date: 25 Jan 93 17:17:46 GMT
  7. Article-I.D.: scotmhs.4DHyXB1w165w
  8. References: <9301220523.AA25652@acme.fred.org>
  9. Sender: daemon@cs.utexas.edu
  10. Organization: Scotlandville Magnet High School
  11. Lines: 74
  12. NNTP-Posting-Host: cs.utexas.edu
  13.  
  14. >From acme.fred.org!MAILER-DAEMON  Thu Jan 21 21:23:07 1993 remote from scotmhs
  15. Received: by scotmhs.fred.org (1.65/waf)
  16.     via UUCP; Fri, 22 Jan 93 04:18:16 EST
  17.     for amusgrov
  18. Received: by acme.fred.org (5.65/1.35)
  19.     id AA25652; Thu, 21 Jan 93 21:23:07 -0800
  20. Date: Thu, 21 Jan 93 21:23:07 -0800
  21. From: acme.fred.org!MAILER-DAEMON (Mail Delivery Subsystem)
  22. Subject: Returned mail: User unknown
  23. Message-Id: <9301220523.AA25652@acme.fred.org>
  24. To: scotmhs!amusgrov
  25.  
  26.    ----- Transcript of session follows -----
  27. >>> RCPT To:<comp-lang-pascal@ucbvax.berkeley.edu>
  28. <<< 550 <comp-lang-pascal@ucbvax.berkeley.edu>... User unknown
  29. 550 comp-lang-pascal@ucbvax.berkeley.edu... User unknown
  30.  
  31.    ----- Unsent message follows -----
  32. Received: by acme.fred.org (5.65/1.35)
  33.     id AA25650; Thu, 21 Jan 93 21:23:07 -0800
  34. Received: by scotmhs.fred.org (1.65/waf)
  35.     via UUCP; Thu, 21 Jan 93 11:15:02 EST
  36.     for comp-lang-pascal@ucbvax.berkeley.edu
  37. To: comp-lang-pascal@ucbvax.berkeley.edu
  38. Subject: Needed: A Recursive binary search function
  39. From: amusgrov@scotmhs.fred.org (Aj musgrove)
  40. Message-Id: <kTiqXB1w165w@scotmhs.fred.org>
  41. Date: Thu, 21 Jan 93 11:11:19 EST
  42. Organization: Scotlandville Magnet High School
  43.  
  44. finocchiaroj@merrimack.edu writes:
  45.  
  46. > I need the code for a recursive binary search function and if anyone has or
  47. > knows of one off hand I would really appreciate if you would mail me the
  48. > code for it.
  49. > Thanks,
  50. >     finocchiaroj@merrimack :)
  51.  
  52.  
  53. Ok, it'll be a mirical if this post makes it out of the system, but here 
  54. is the code for the function that you want:
  55.  
  56. First, the type declaration:
  57. TYPE
  58.    st20 = string[20];
  59.    nodeptr = ^node;
  60.    node = RECORD
  61.           data : st20;
  62.           left, right : nodeptr;
  63.           END;
  64.  
  65. Now, the 'find' (search) procedure:
  66. PROCEDURE Find( Tree : nodeptr; VAR loc : nodeptr; tofind : st20 );
  67. BEGIN
  68.    IF tree <> nil THEN
  69.    BEGIN
  70.       IF tofind = tree^.data THEN loc := tree
  71.       ELSE
  72.          if tofind < tree^.data THEN find(tree^.left,loc,tofind) ELSE
  73.             find(tree^.right,loc,tofind);
  74.    END;
  75. END;
  76.  
  77. The original parameter 'loc' should be nil. Tofind is the search string, 
  78. and the original Tree is the root of your tree. If you follow the logic 
  79. of binary trees, then you will see that It decides 'higher' or 'lower' 
  80. and goes that way, until it finds what it is looking for, or runs out of 
  81. places to look.
  82.  
  83. It will return a pointer to the proper node in 'loc', or 'loc = nil' if 
  84. it isn't found.
  85.  
  86. AJ
  87.