Question
This program is IN THE C LANGUAGE! I WILL THUMBS UP THE ANSWER IF CORRECT!!:) PLEASE USE THE PROVIDED FUNCTIONS GIVEN BELOW! Please if possible,
This program is IN THE C LANGUAGE! I WILL THUMBS UP THE ANSWER IF CORRECT!!:)
PLEASE USE THE PROVIDED FUNCTIONS GIVEN BELOW! Please if possible, have comments within the code!
Please convert the following 2 functions from using iteration to loop, to use recursion (call the function within the function). Functionally, the code must do the same exact thing as below; however the functions will call themselves instead of having the loops. Thank you!
#include
#include
#include
#include
// The struct that both functions will use
struct employee {
int number;
char name [20];
};
/**
The "find_number" function searches for an employee number within an array of employees. If the employee was found with that number, true is returned to main and the string "found_employee" (in main) is set to the name that was found. By using recursion, this function must run O (n) times if the name is last in the array and O (1) times if the name was first in the array.
**/
bool find_number(int number, struct employee arr[], int n, char * found_employee);
/**
The "find_employee" function searches for a certain employee name within an array of employees. If one or more employees where found with that name (there can be more than 1 employee with the same name), the total numbers of employees with the same name will be returned to main and the array "ids[]" will be updated to have the employee ID's (of the ones with the same name found). If none where found, 0 will be returned. By using recursion, this function must run O (n) times to check all names.
**/
int find_employee(char * employee_name , struct employee arr[], int n, int numbers[]);
bool find_number(int number, struct employee arr[], int n, char * found_employee){
int i;
for(i=0; i if (number==arr[i].number) { strcpy(found_employee,arr[i].name); return true; } } return false; } int find_employee(char * employee_name , struct employee arr[], int n, int numbers[]){ int i; int j; int sameEmployeeNames=0; for(i=0; i if (strcmp(employee_name, arr[i].name)==0) { numbers[sameEmployeeNames] = arr[i].number; sameEmployeeNames ++; } } return sameEmployeeNames; } //Here is an example of the inputs to the functions struct employee e1 = {1234567, "TestEmployee"};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started