0

I have a binary tree and each node has this footprint. The tree is balanced by the key.

struct node
{
   STRING key;
   VECTOR data;
   struct node left;
   struct node right;
}

I want to have a function that will return the key of a node that has the largest data vector. size(data) returns the size of the data; I want to use such a function like STRING largest = get_largest_key(MYTREE); Thank you.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

You can also obtain a traversal of your tree, and then perform a linear search. I can't think of a faster method, since your tree is ordered by the key, not by the size of data.

rw.liang1
  • 418
  • 4
  • 12
  • Do you mind providing some basic code to do this? I'm drawing a blank. Thanks – user3576699 Apr 26 '14 at 18:35
  • @user3576699 I just saw your pastebin link. The code in it seems to be solid. What problems are you running into? – rw.liang1 Apr 26 '14 at 18:53
  • GCC was giving me a warning about control reaches end of non-void function [-Wreturn-type]. If I add return NULL at the end to fix the warning it breaks the whole thing. I thought this code was actually sub-human scum. – user3576699 Apr 26 '14 at 18:54