Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having problems with the recursive functions. Any help on the recursive fun

ID: 3789451 • Letter: I

Question

I am having problems with the recursive functions. Any help on the recursive functions would be awesome! Thank you!

Create two unrelated recursive functions mysort and hilo. While either of these functions could be implemented iteratively, this project will assist you in mastering simple recursion void my sort (int nums int nelems) This function sorts an array integer by finding the minimum element, swapping it with the first element, and then repeating the process on the rest of the array, recursively, until the entire array is sorted You will need a recursive helper function that takes three parameters the array, the numeric index of the first element in the array (0 on the first call), and the size of the array at the moment (the number of elements in the first call) The stopping condition is an array of size 0. The second function is void hilo (int size This function initiates a guessing game, where the user thinks of a number between 1 and size and the program tries to guess it It uses a binary-search-type approach by first guessing the number in the middle of the range C1, size J. The user responds to the guess by saying whether it is too low (l), too high (h), or correct (y) All of the work is done in the helper function which takes the first and last numbers in the current range of possible numbers ([1,size] to start; hilo just calls the helper function with these parameters after printing an initial greeting After the user responds the helper function either quits with a success message if the guess is correct calls itself recursively on the remaining larger numbers if the guess was too low calls itself recursively on the remaining smaller numbers if the guess was too high You will also need to detect if the user cheated. This is done by simply detecting whether there are no numbers left to try. The stopping condition for your helper function is, therefore, one of the following the user entered 'y there is only one number left in the list (which should be correct) there are no numbers left to try

Explanation / Answer

HI, Please find the implementation of first method.

Please repost second in separate post.

Please let me know in case of any issue in first function.


void mysortHelper(int[] nums, int startIndex, int nelems)
{
if ( startIndex >= nelems - 1 )
return;
int minIndex = startIndex;
for ( int index = startIndex + 1; index < nelems; index++ )
{
if (nums[index] < nums[minIndex] )
minIndex = index;
}
int temp = nums[startIndex];
nums[startIndex] = nums[minIndex];
nums[minIndex] = temp;
mysortHelper(nums, startIndex + 1, nelems);
}

void mysort(int[] nums, int nelems)
{
mysortHelper(nums, 0, nelems);
}