public Tree ancestor ( int height , Tree root ) { if ( height < 0 ) { throw new IllegalArgumentException ( "ancestor: height cannot be negative" ) ; } if ( height == 0 ) { return this ; } Tree par = parent ( root ) ; if ( par == null ) { return null ; } return par . ancestor ( height - 1 , root ) ; }
Returns the ancestor of the given tree