2015-03-25 5 views
1

Я должен реализовать форму 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 { 

    } 
} 

Это то, что мне удалось сделать до сих пор, но я не знаю, как реализовать установленные методы.

ответ

0

Я думаю, что это будет хорошо для работника одного и того же уровня:

public void setEmployee(Person e1) { 
if (nextEmployee == null) { 
    nextEmployee = new Node(e1, this.seniorEmployee); 
} else { 
    nextEmployee.setEmployee(e1); 
} 

}

Смежные вопросы