Question: I ' m writing a call function for a C + + program, please read the requirements and help me complete the following call function,

I'm writing a call function for a C++ program, please read the requirements and help me complete the following call function, thanks:
TODO: Complete the missing blocks/lines in this recursive function find_path() that takes the following parameters:
stage: a 2D array of C strings that represents the towers and floors. Each tower has at most 4 floors, and each floor has a encounter in C string.
num_tower: the number of towers.
current_tower: the current tower number (counts from 0).
num_floor: the number of floors in each tower.
explored_floor_count: the number of floors that have been explored in the current tower.
explored_floor: an array of integers that contains the floor numbers of the explored floors in the current tower.
strength: the current strength.
floor_path: an array of integers that you will write the best path for this tower given the floor you explored. Use it as pass-by-reference to return the path.
stage_path: a 2D array of integers that you will write the best path for this stage. Use it as pass-by-reference to return the best path. You may want to write it every time you finish a tower.
The function should return the highest strength that you can achieve in this stage, i.e., the strength after taking the best path.
int find_path(int tower[][MAX_NUM_FLOOR], int floor_explored[], int floor_path[], int best_floor_path[], int tower_index){
if (tower_index >= MAX_NUM_TOWER){
return 0; // No more towers to explore
}
int highest_strength =0;
for (int i =0; i < MAX_NUM_FLOOR; ++i){
int recursion_floor_path[MAX_NUM_FLOOR];
copy_floor(recursion_floor_path, floor_path);
// Calculate strength for the current floor and call recursively for the next tower
int current_strength = tower[tower_index][i];
int recursion_result = current_strength + find_path(tower, floor_explored, recursion_floor_path, best_floor_path, tower_index +1);
if (recursion_result > highest_strength){
highest_strength = recursion_result;
copy_floor(best_floor_path, recursion_floor_path);
best_floor_path[tower_index]= i; // Track the best floor for each tower
}
}
return highest_strength;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!