DiTeN
December 18th, 2009, 02:58 AM
Hello friends,
i want to know if could help me how to print an AVL Tree, by levels, and from left to right and from right to left
and if could insert duplicated items,
i have this insert... which does not allowes duplicated....
private AvlNode<AnyType> insert( AnyType x, AvlNode<AnyType> t )
{ int cont=1;
if( t == null )
return new AvlNode<AnyType>( x, null, null );
int compareResult = x.compareTo( t.element );
if( compareResult < 0 )
{
t.left = insert( x, t.left );
if( height( t.left ) - height( t.right ) == 2 )
if( x.compareTo( t.left.element ) < 0 )
t = rotateWithLeftChild( t );
else
t = doubleWithLeftChild( t );
}
else if( compareResult > 0 )
{
t.right = insert( x, t.right );
if( height( t.right ) - height( t.left ) == 2 )
if( x.compareTo( t.right.element ) > 0 )
t = rotateWithRightChild( t );
else
t = doubleWithRightChild( t );
}
else
//; // Duplicate; do nothing
t.height = Math.max( height( t.left ), height( t.right ) ) + 1;
return t;
}
as far i been reading i find that i need a counter, but my english isn't well and i can't catch everything....
i will be very thankful if you people can help me...
thanks a lot!!!
sorry for my bad english!!!
i want to know if could help me how to print an AVL Tree, by levels, and from left to right and from right to left
and if could insert duplicated items,
i have this insert... which does not allowes duplicated....
private AvlNode<AnyType> insert( AnyType x, AvlNode<AnyType> t )
{ int cont=1;
if( t == null )
return new AvlNode<AnyType>( x, null, null );
int compareResult = x.compareTo( t.element );
if( compareResult < 0 )
{
t.left = insert( x, t.left );
if( height( t.left ) - height( t.right ) == 2 )
if( x.compareTo( t.left.element ) < 0 )
t = rotateWithLeftChild( t );
else
t = doubleWithLeftChild( t );
}
else if( compareResult > 0 )
{
t.right = insert( x, t.right );
if( height( t.right ) - height( t.left ) == 2 )
if( x.compareTo( t.right.element ) > 0 )
t = rotateWithRightChild( t );
else
t = doubleWithRightChild( t );
}
else
//; // Duplicate; do nothing
t.height = Math.max( height( t.left ), height( t.right ) ) + 1;
return t;
}
as far i been reading i find that i need a counter, but my english isn't well and i can't catch everything....
i will be very thankful if you people can help me...
thanks a lot!!!
sorry for my bad english!!!