Я должен реализовать форму binary tree
где он показывает иерархию занятости, где босс - корень деревьев, а меньший сотрудник - левый узел, а правый узел - работник того же уровня. Сотрудники на одном уровне размещаются в соответствии со своим номером сотрудника.
public class Node {
private Person data;
private Node seniorEmployee;
private Node nextEmployee;
private Node lesserEmployee;
public Node(Member data, Node seniorEmployee) {
this.data = data;
this.seniorEmployee = seniorEmployee;
this.nextEmployee = null;
this.lesserColleague = null;
}
public Member getPerson() {
return this.data;
}
public Node getSeniorEmployee() {
return this.seniorEmployee;
}
public Node getNextEmployee() {
return this.nextEmployee;
}
public Node getLesserEmployee() {
return this.lesserEmployee;
}
public void setEmployee(Person e1) {
if (nextEmployee == null) {
nextEmployee = new Node(e1, this.seniorEmployee);
} else {
if (e1.compareTo(nextEmployee.getPerson()) > 0) {
} else {
}
}
public void setLesserEmployee(Member p1) {
if (lesserEmployee == null) {
lesserEmployee = new Node(e1, this.seniorEmployee);
} else {
if (e1.compareTo(lesserEmployee.getPerson()) > 0) {
} else {
}
}
Это то, что мне удалось сделать до сих пор, но я не знаю, как реализовать установленные методы.
Я думаю, что это будет нормально для сотрудника того же уровня:
public void setEmployee(Person e1) {
if (nextEmployee == null) {
nextEmployee = new Node(e1, this.seniorEmployee);
} else {
nextEmployee.setEmployee(e1);
}
}