home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18861 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  2.1 KB

  1. Path: sparky!uunet!usc!rpi!batcomputer!cornell!uw-beaver!cs.ubc.ca!unixg.ubc.ca!unixg.ubc.ca!rudolph
  2. From: rudolph@unixg.ubc.ca (Christopher E Rudolph)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Binary Tree Problem!
  5. Date: 24 Nov 92 03:53:20 GMT
  6. Organization: The University of British Columbia
  7. Lines: 62
  8. Message-ID: <rudolph.722577200@unixg.ubc.ca>
  9. NNTP-Posting-Host: unixg.ubc.ca
  10. Summary: I am having a problem with some binary search functions if anyone is in
  11. Keywords: binary tree problem
  12.  
  13. I seem to be having a problem with getting a returned value back after a
  14. call to insert a node on a binary tree.
  15.  
  16. I initially call the function BRANCH *insert_on_tree (DATA *dat)
  17.  
  18. where BRANCH is a typedef struct to attach to the list and DATA is some data
  19.  
  20. Here is how I do it:
  21.  
  22. BRANCH *insert_on_tree (DATA *dat)
  23. {
  24.    BRANCH *a;
  25.    
  26.    a = root;  /* assign a to point to what the roo points to */
  27.   .
  28.   .
  29.   .
  30.  
  31.    if (recursive_search (a, dat)) /* a should now be attached to the tree *?
  32.    {
  33.       a->info = *dat;
  34.       return a;
  35.    }
  36.  
  37.    return NULL; /* everything failed */
  38. }
  39.  
  40. .
  41. .
  42. .
  43.  
  44. int recursive_search (BRANCH *bra, DATA *dat)
  45. {
  46.    BRANCH  *temp;
  47.    int result;
  48.  
  49.    result = strcmp ((bra->info.last_name), (dat->last_name));
  50.    if (result >= 0)
  51.    {
  52.       /** we need to search on the left node **/
  53.      if (bra->left_child == NULL)
  54.      {
  55.        bra->left_child = create_node ();
  56.        bra = bra->left_child;
  57.        return;
  58.      }
  59.  
  60.       Okay, since I haven't been able to get past the first two data items
  61.       I find myself here.  Everything goes as planned,  bra points to what
  62.       I want it to, however, upon return, "a" doesn't point to the same
  63.       as "bra" did before it exited, obviously I'm not setting a, however
  64.      I thought that I was working with a to begin with.
  65.  
  66.        If anyone can help me out here I would appreciate it Email me if you
  67.      would please.
  68.  
  69. thanks in advance,
  70.  
  71. -------------------------------------------------------------------------
  72. ||||||||| Chris Rudolph (CompSci, UBC) <rudolph@unixg.ubc.ca> |||||||||||||
  73. --------------------------------------------------------------------------
  74.  
  75.