Question
Please Explain and show output. (array.c) #include #include #include int* bubbleSort(int arr[], int n){ int temp, i = 0, j = 0; int *s_arr =
Please Explain and show output.
(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[i] = arr[i]; // Actual sorting using array notations // Comment this when implementing pointer version. for (i=0;i for(j=0;j if(s_arr[j] > s_arr[j+1]){ temp = s_arr[j+1]; s_arr[j+1] = s_arr[j]; s_arr[j] = temp; } } } // Actually 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 printf("%d ", arr[i]); printf("] "); } int bSearch(int *arr, int a, int b, int key){ // Binary search function. arr is the array, key is the value to search for, a and b are the boundaries of arr to be searched within. // You must use pointer notations. i.e. no "[]" // Your code goes here: return 0; // Modify this to return an appropriate value! } int main() { int i = 0, size = 0, key = 0, result = 0; int *array, *sorted; printf("How big is your array? "); scanf("%d", &size); array = (int*)malloc(size * sizeof(int)); for(i=0; i printf("Please enter array[%d]: ", i); scanf("%d", &array[i]); } printf("Please wait while I sort your numbers... "); sorted = bubbleSort(array, size); printf("Here is your original array: "); printArray(array, size); printf("Here is your SORTED array: "); printArray(sorted, size); printf("What number are you looking for? "); scanf("%d", &key); printf("OK, let me see if I can find a \"%d\" in the array... ", key); result = bSearch(sorted, 0, size-1, key); if(result != -1) printf("Got it! A \"%d\" is at index %d. ", key, result); else printf("I'm sorry, a \"%d\" cannot be found in the array. ", key); return 0; }
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