Subversion Repositories programming

Rev

Rev 29 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29 Rev 30
Line 86... Line 86...
86
    }
86
    }
87
 
87
 
88
    //toString method -------------------------------------------------------
88
    //toString method -------------------------------------------------------
89
 
89
 
90
    // returns a String representation of the BinaryTree
90
    // returns a String representation of the BinaryTree
-
 
91
    // Precondition:  none
-
 
92
    // Postcondition: returns a string representation of the BinaryTree
91
    public String toString() { 
93
    public String toString() { 
92
        String sLeft = "";
94
        String sLeft = "";
93
        String sRight = "";
95
        String sRight = "";
94
        String answer = new String();
96
        String answer = new String();
95
        
97
        
96
        //check left tree
98
        //get the left tree's string representation (if it exists)
97
        if( !(left == null) ) { sLeft = left.toString(); }
99
        if( !(left == null) ) { sLeft = left.toString(); }
98
        
100
        
99
        //check right tree
101
        //get the right tree's string representation (if it exists)
100
        if( !(right == null) ) { sRight = right.toString(); }
102
        if( !(right == null) ) { sRight = right.toString(); }
101
 
-
 
102
        //answer = "(" + sLeft + "," + root.toString() + "," + sRight + ")";
-
 
103
        
103
        
-
 
104
        //assemble the string to return
104
        answer = "(";
105
        answer = "(";
105
        if( !sLeft.equals("") ) { answer += sLeft + ","; }
106
        if( !sLeft.equals("") ) { answer += sLeft + ","; }
106
        answer += root.toString();
107
        answer += root.toString();
107
        if( !sRight.equals("") ) { answer += "," + sRight; }
108
        if( !sRight.equals("") ) { answer += "," + sRight; }
108
        answer += ")";
109
        answer += ")";
109
        
110
        
-
 
111
        //return the assembled string
110
        return answer;
112
        return answer;
111
    }
113
    }
112
    /*
114
    
113
    //misc methods ----------------------------------------------------------
115
    //misc methods ----------------------------------------------------------
114
    public boolean isLeaf() { }
116
    public boolean isLeaf() { 
-
 
117
        if( left == right == null ) { return true; }
-
 
118
        return false;
-
 
119
    }
115
    public int size() { }
120
    public int size() { }
116
    public int height() { }
121
    public int height() { }
117
    public boolean contains( Object object ) { }
122
    public boolean contains( Object object ) { }
118
    public int numLeaves() { }
123
    public int numLeaves() { }
119
    public int count( Object x ) { }
124
    public int count( Object x ) { }