alsalaam 3likom
I'm not sure if this code is correct or not.
could you please help me to make sure if it is right or not.
I want to generate AVL tree function of height h with fewest nodes.
here is the code
template <class Comparable>
void AvlTree<Comparable>::generate( const Comparable & h, AvlNode<Comparable> * & t )
{
if( t == NULL )
t = new AvlNode<Comparable>( "", NULL, NULL);
else {if( height( t->left ) < height( t->right ) )
insert( t->left )
else if( height( t->left ) > height( t->right ) )
insert( t->right );
else
if( height( t->left ) == height( t->right ) )
insert( t->left );
t->height = max( height( t->left ), height( t->right ) ) + 1;
if (height!=h)
generate(h,t)
}