home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rpi!batcomputer!cornell!uw-beaver!cs.ubc.ca!unixg.ubc.ca!unixg.ubc.ca!rudolph
- From: rudolph@unixg.ubc.ca (Christopher E Rudolph)
- Newsgroups: comp.sys.mac.programmer
- Subject: Binary Tree Problem!
- Date: 24 Nov 92 03:53:20 GMT
- Organization: The University of British Columbia
- Lines: 62
- Message-ID: <rudolph.722577200@unixg.ubc.ca>
- NNTP-Posting-Host: unixg.ubc.ca
- Summary: I am having a problem with some binary search functions if anyone is in
- Keywords: binary tree problem
-
- I seem to be having a problem with getting a returned value back after a
- call to insert a node on a binary tree.
-
- I initially call the function BRANCH *insert_on_tree (DATA *dat)
-
- where BRANCH is a typedef struct to attach to the list and DATA is some data
-
- Here is how I do it:
-
- BRANCH *insert_on_tree (DATA *dat)
- {
- BRANCH *a;
-
- a = root; /* assign a to point to what the roo points to */
- .
- .
- .
-
- if (recursive_search (a, dat)) /* a should now be attached to the tree *?
- {
- a->info = *dat;
- return a;
- }
-
- return NULL; /* everything failed */
- }
-
- .
- .
- .
-
- int recursive_search (BRANCH *bra, DATA *dat)
- {
- BRANCH *temp;
- int result;
-
- result = strcmp ((bra->info.last_name), (dat->last_name));
- if (result >= 0)
- {
- /** we need to search on the left node **/
- if (bra->left_child == NULL)
- {
- bra->left_child = create_node ();
- bra = bra->left_child;
- return;
- }
-
- Okay, since I haven't been able to get past the first two data items
- I find myself here. Everything goes as planned, bra points to what
- I want it to, however, upon return, "a" doesn't point to the same
- as "bra" did before it exited, obviously I'm not setting a, however
- I thought that I was working with a to begin with.
-
- If anyone can help me out here I would appreciate it Email me if you
- would please.
-
- thanks in advance,
-
- -------------------------------------------------------------------------
- ||||||||| Chris Rudolph (CompSci, UBC) <rudolph@unixg.ubc.ca> |||||||||||||
- --------------------------------------------------------------------------
-
-