Question: array.c #include #include #include int* bubbleSort(int arr[], int n) { int temp, i = 0, j = 0; int *s_arr = (int*)malloc(n * sizeof(int)); //

array.c #include #include #include int* bubbleSort(int arr[], int n) { int temp,array.c

#include #include #include int* bubbleSort(int arr[], int n) { int temp, i = 0, j = 0; int *s_arr = (int*)malloc(n * sizeof(int)); // Copy arr to s_arr for(i = 0; i s_arr[j + 1]) { temp = s_arr[j + 1]; s_arr[j + 1] = s_arr[j]; s_arr[j] = temp; } } } // Sorting using pointer notations. i.e. you cannot use "[]"! // Your code goes here... return s_arr; } void printArray(int arr[], int n) { int i = 0; printf("["); for(i = 0; i

array = (int*)malloc(size * sizeof(int)); for(i = 0; i

Jse array. c (shown below) to complete the tasks below. 1. This program will store integers entered by a user into an array. It then calls bubblesort to sort the array. Read the code to answer the questions below. a. Why do we need to pass the size of the array to the function? b. Is the original array (the one being passed into the function) changed at the end of this function? c. Why do you think a new array (s_array) is needed to store the result of the sorted values (why not update the array as we sort)? Hint: look at what the main function does. 2. Once you understand how Bubble Sort works, rewrite the code so that you are accessing the array's content using pointer notation (* _arr ), i.e. you cannot use s_arr [j] anymore. Comment out the original code so the algorithm does not run twice. 3. After the array is sorted, the program will ask the user to enter a key to search for in the sorted array. It will then call bsearch to perform a Binary Search on the array. Complete the bsearch function so that it implements Binary Search recursively (no loop!). You must use pointer notation here too. Pay attention to what is written in main so your bsearch will return an appropriate value

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 Databases Questions!