I want to compare between nodes in BST to find the highest salary and im using recursion function in implementing my BST.
Below is the question:
A company needs to keep all records of its employees. Employee record should
contain employee id(4 digit integer numbers), name, department, salary and
an employee phone number. Using bst, write a program to do the following tasks:
- Insert data. (Arrange by employee id).
- Display all data.
- Display data of all employees from the same department.
- Display the employee with the highest salary.
- Count and display how many employee have salary > 10000
- Display the total salary of all employees.
- Display the average salary.
*no data duplication
So this is my code for finding the highest salary. It doesn't give the correct output.
public void highestSalary()
{
System.out.println("\n<EMPLOYEE WITH HIGHEST SALARY>\n");
Employee highestEmployee = new Employee();
Employee highestEmp = highestSalaryHelper(root, 0.0, highestEmployee);
System.out.println(highestEmp.toString());
}
public Employee highestSalaryHelper(TreeNode node, double hS, Employee hE)
{
if(node.left!=null)
{
if(node.data.getSalary()>hS)
{
hS = node.data.getSalary();
hE = node.data;
}
else
{
highestSalaryHelper(node.left, node.left.data.getSalary(), hE);
}
}
if(node.right!=null)
{
if(node.data.getSalary()>hS)
{
hS = node.data.getSalary();
hE = node.data;
}
else
{
highestSalaryHelper(node.right, node.right.data.getSalary(), hE);
}
}
return node.data;
}
}