Package edu.neu.khoury.cs6510.f24.wp161
Class Node
java.lang.Object
edu.neu.khoury.cs6510.f24.wp161.Node
The Node class represents a single node in a binary tree.
Each node contains an integer value, a reference to its left child,
and a reference to its right child.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this node to another object for equality.getLeft()Returns the left child of this node.getRight()Returns the right child of this node.getValue()Returns the integer value stored in this node.inthashCode()Returns a hash code value for this node.booleanisLeaf()Determines if this node is a leaf node.voidSets the left child of this node.voidSets the right child of this node.voidSets the integer value of this node.toString()Returns a string representation of the node, including its value, left child, and right child.
-
Constructor Details
-
Node
Constructs a new Node with a given integer value.- Parameters:
value- the integer value to be stored in the node, must not be null- Throws:
IllegalArgumentException- if the value is null
-
-
Method Details
-
getValue
Returns the integer value stored in this node.- Returns:
- the value of the node
-
setValue
Sets the integer value of this node.- Parameters:
value- the new integer value to be set
-
getLeft
Returns the left child of this node.- Returns:
- the left child node, or null if no left child exists
-
setLeft
Sets the left child of this node.- Parameters:
left- the node to be set as the left child
-
getRight
Returns the right child of this node.- Returns:
- the right child node, or null if no right child exists
-
setRight
Sets the right child of this node.- Parameters:
right- the node to be set as the right child
-
isLeaf
public boolean isLeaf()Determines if this node is a leaf node. A node is considered a leaf node if it has no left or right children.- Returns:
- true if the node is a leaf (both left and right children are null), false otherwise
-
toString
Returns a string representation of the node, including its value, left child, and right child. -
equals
Compares this node to another object for equality. Two nodes are considered equal if they have the same value, left child, and right child. -
hashCode
public int hashCode()Returns a hash code value for this node. The hash code is generated based on the node's value, left child, and right child.
-