first commit
This commit is contained in:
150
CS1322/t5/BSTNode.java
Normal file
150
CS1322/t5/BSTNode.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* <PRE>
|
||||
* BSTNode.java
|
||||
*
|
||||
* Revisions: 1.0 Oct. 16, 2002
|
||||
* Created the BSTNode class
|
||||
* 1.1 Oct. 19, 2002
|
||||
* Compiled, Finished
|
||||
* 1.2 Oct. 27, 2002
|
||||
* Commented
|
||||
*
|
||||
* </PRE>
|
||||
*
|
||||
* Collaboration Statement:
|
||||
* I worked on the homework assignment alone, using only
|
||||
* course materials.
|
||||
*
|
||||
* Created with JCreatorLE, some indents are off when viewed through notepad
|
||||
* or EMACS
|
||||
*
|
||||
* @author <A HREF="mailto:gtg184g@mail.gatech.edu">Jose Manuel Caban</A>
|
||||
* @version Version 1.2, Oct. 27, 2002
|
||||
*/
|
||||
|
||||
public class BSTNode implements Comparable{
|
||||
|
||||
public static final boolean bDebug = false; //nothing to debug
|
||||
|
||||
private Comparable data;
|
||||
private BSTNode left;
|
||||
private BSTNode right;
|
||||
|
||||
////////////////
|
||||
//Constructors//
|
||||
////////////////
|
||||
|
||||
/**
|
||||
*Default Constructor
|
||||
*/
|
||||
public BSTNode(){
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
*@param data, the value of data
|
||||
*/
|
||||
public BSTNode(Comparable data){
|
||||
this.data = data;
|
||||
left = null;
|
||||
right = null;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////
|
||||
//Accessors/Modifiers//
|
||||
///////////////////////
|
||||
|
||||
/**
|
||||
*Accessor for data
|
||||
*@return value of data
|
||||
*/
|
||||
public Comparable getData(){
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
*Modifier for data
|
||||
*@param the value of data
|
||||
*/
|
||||
public void setData(Comparable data){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
*Accessor for left
|
||||
*@return value of left
|
||||
*/
|
||||
public BSTNode getLeft(){
|
||||
return left;
|
||||
}
|
||||
|
||||
/**
|
||||
*Modifier for left
|
||||
*@param the value ofleft
|
||||
*/
|
||||
public void setLeft(BSTNode left){
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
/**
|
||||
*Accessor for right
|
||||
*@return value of right
|
||||
*/
|
||||
public BSTNode getRight(){
|
||||
return right;
|
||||
}
|
||||
|
||||
/**
|
||||
*Modifier for right
|
||||
*@param the value ofright
|
||||
*/
|
||||
public void setRight(BSTNode right){
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
///////////
|
||||
//Methods//
|
||||
///////////
|
||||
|
||||
/**
|
||||
*compareTo method
|
||||
*@return the value of data's compareTo()
|
||||
*/
|
||||
public int compareTo(Object o){
|
||||
if(o instanceof BSTNode){
|
||||
BSTNode temp = (BSTNode)o;
|
||||
return data.compareTo(temp.getData());
|
||||
}
|
||||
else{
|
||||
throw new ClassCastException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*toString() method
|
||||
*@return data's toString()
|
||||
*/
|
||||
public String toString(){
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging main for class BSTNode.
|
||||
* This method will rigorously test my code.
|
||||
*
|
||||
* <br><br>
|
||||
* @param args a String array of command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
BSTNode bob = new BSTNode(new Integer(7));
|
||||
BSTNode rob = new BSTNode(new Integer(7));
|
||||
BSTNode tod = new BSTNode(new Integer(6));
|
||||
|
||||
System.out.println(bob.compareTo(rob));
|
||||
System.out.println(bob.compareTo(tod));
|
||||
System.out.println(bob.toString());
|
||||
|
||||
}// end of main(String[] args)
|
||||
|
||||
}// end of class BSTNode
|
||||
Reference in New Issue
Block a user