-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.java
35 lines (30 loc) · 1023 Bytes
/
Node.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
public class Node<T>
{
Node(Comparable<T> element)
{
this.element = element;
this.left = null;
this.right = null;
}
Node(Comparable<T> element, Node left, Node right)
{
this.element = element;
this.left = left;
this.right = right;
}
Comparable<T> element; // Key
Node left; // Left child
Node right; //Right child
public int compareTo(Node node)
{
if (this.element.getClass() != null && node.element.getClass() != null)
{
if ((this.element.getClass().equals(Integer.TYPE)) || (this.element.getClass().equals(Double.TYPE)) || (node.element.getClass().equals(String.class)))
this.element = (Comparable<T>) this.element;
if ((node.element.getClass().equals(Integer.TYPE)) || (node.element.getClass().equals(Double.TYPE)) || (node.element.getClass().equals(String.class)))
node.element = (Comparable<T>) node.element;
}
return (this.element).compareTo((T) node.element);
}
}