Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not.
//PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp, and returns // false otherwise. An empty array returns false. Method employeeInRec must be recursive and returns true if array csEmployees has employee emp, and returns false otherwise. public boolean employeeInRec (Employee[] csEmployees, int n, Employee emp) { } |
public boolean employeeInRec (Employee[] csEmployees, int n,
Employee emp)
{
if(csEmployees.length==0)//if array
is empty
return false;
if(n==0)//if emp not found
return false;
if(csEmployees[n-1].equals(emp))//if emp found
return true;
return
employeeInRec(csEmployees,n-1,emp);//recursive call
}
Get Answers For Free
Most questions answered within 1 hours.