public class LinkedList
{
private Node list;
public LinkedList()
{
list = null;
}
public Node getList()
{
return list;
}
. . .//other methods
// insert method printHighEarners here
// insert method lowestPaidEmployeeRec
private class Node
{
public Employee data;
public Node next;
public Node(Employee emp)
{
data = emp;
next = null;
}
public String toString()
{
return data.toString();
}
}
}
11) Write a recursive method lowestPaidEmployeeRec that is placed in the linked list after the method countHighEarners. Method returns employee with lowest salary in entire linked lists of employees. Assume the same LinkedList class as is given as in question 10 above.
// PRECONDITION: Linked list is not empty.
public Employee lowestPaidEmployeeRec(Node first) // first is reference to the beginning of linked list. { } |
The recursive method for getting lowest paid employee is given below.
public Employee lowestPaidEmployeeRec(Node first) // first is
reference to the beginning of linked list.
{
if(first.next == null)
return first.data;
else{
Employee e1 = first.data;
Employee e2 =
lowestPaidEmployeeRec(first.next);
if(e1.getSalary() <
e2.getSalary())
return e1;
else
return e2;
}
}
Get Answers For Free
Most questions answered within 1 hours.