Given the follow AVL tree:
2007
/ \
/ \
2005 2010
/ \ \
/ \ \
2003 2006 2012
How can I get the N biggest nodes?
Example input: 4
Example output: {2012, 2010, 2007, 2006}
I only managed to get the biggest node by doing this:
node* findMax(node* t)
{
if(t == NULL)
return NULL;
else if(t->right == NULL)
return t;
else
return findMax(t->right);
}
But I'm unable to get the N biggest nodes.
Cheers!
Comments
Post a Comment