-
Notifications
You must be signed in to change notification settings - Fork 0
/
TNode.java
70 lines (57 loc) · 1.5 KB
/
TNode.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* This is the TNode class.
* @author Wei Zhong Tee
* @since 8 May 2020
*/
public class TNode {
private String item;
private TNode parent;
private int depth;
/**
* This is the constructor to be used for the original word the user inputs
* @param firstWord The first word the user input
*/
public TNode(String firstWord) {
this.item = firstWord;
this.depth = 0;
}
/**
* This is the constructor that is used for the word permutations
* It also sets the depth of the TNode by using the value of the incremented the parent TNode depth
* @param currentWord The current word permutations
* @param before The parent TNode word
*/
public TNode(String currentWord, TNode before) {
this.item = currentWord;
this.parent = before;
this.depth = parent.getDepth() + 1;
}
/**
* This method gets the parent node of the current node
* @return The parent TNode
*/
public TNode getParent() {
return this.parent;
}
/**
* Returns the current word permutation
* @return The current word permutation as a string
*/
public String getItem() {
return this.item;
}
/**
* The toString method for the TNode class
* @return returns the TNode item as a string
*/
public String toString() {
return this.item.toString();
}
/**
* Returns the depth of the TNode in the tree
* @return The depth integer
*/
public int getDepth() {
return this.depth;
}
}