Return the difference between the lowest and highest key

Posted by stan on Stack Overflow See other posts from Stack Overflow or by stan
Published on 2010-05-12T15:55:31Z Indexed on 2010/05/12 16:04 UTC
Read the original article Hit count: 122

Filed under:
|
|
|
|

This is a past exam paper i am attempting and have no way to check if the out put is correct as i am not capable of building one of these things

the question is in the title

class Tree{
    Tree left;
    Tree right;
    int key;

   public static int span(Tree tree)
   {
        if ( tree == null ){
             return null;
        }

        if( tree.left != null)
             int min = span(tree.left);
         }

        if( tree.right != null){
             int max = span(tree.right);
         }
         return max - min;
    }
}

Could anyone suggest what i need to change to get 5/5 marks :D - the only thing we have to do is write the span method, the header was given for us

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about binary