-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTreeNode.java
More file actions
57 lines (48 loc) · 1.4 KB
/
TreeNode.java
File metadata and controls
57 lines (48 loc) · 1.4 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.LinkedList;
/*
Authors (group members): Dan Levy, Daniel Griessler, and Frank Savino
Email addresses of group members: dlevy2016@my.fit.edu, dgriessler2016@my.fit.edu, and fsavino2018@my.fit.edu
Group name: Group 2b
Course: CSE 2010
Section: 02
Description of the overall algorithm and key data structures:
* Creates a node for a tree data structure
* Includes the node's element, the node's parent, and the node's children
*/
public class TreeNode<E> implements Comparable<TreeNode<E>> {
private E _element;
private TreeNode<E> _parent;
private LinkedList<TreeNode<E>> _children;
private Position _position;
// Creates a new node
public TreeNode(E element, TreeNode<E> parent, Position position) {
this._element = element;
this._parent = parent;
_children = new LinkedList<TreeNode<E>>();
this._position = position;
}
// Gets the node's element
public E getElement() {
return this._element;
}
public Position getPosition() {
return this._position;
}
// Gets the node's parent
public TreeNode<E> getParent() {
return this._parent;
}
// Gets the node's children
public LinkedList<TreeNode<E>> getChildren() {
return this._children;
}
// Compare two node's for lexicographical ordering
@Override
public int compareTo(TreeNode<E> o) {
return this.getPosition().compareTo(o.getPosition());
}
@Override
public String toString() {
return this._element.toString();
}
}