Question: can you help me fix this code? #include int insertionSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr); int selectionSort(int arr[], int size, int* ncompares_ptr, int*

can you help me fix this code?

#include

int insertionSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr);

int selectionSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr);

int bubbleSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr);

int main(){

int arr1[5] = {1,2,3,4,5};

int arr2[5] = {5,4,3,2,1};

int arr3[5] = {2,1,4,3,5};

int compare=0;

int swap =0;

printf("BubbleSort ");

bubbleSort(arr1,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

bubbleSort(arr2,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

bubbleSort(arr3,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

int arr4[5] = {1,2,3,4,5};

int arr5[5] = {5,4,3,2,1};

int arr6[5] = {2,1,4,3,5};

compare=0;

swap =0;

printf("InsertionSort ");

insertionSort(arr4,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

insertionSort(arr5,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

insertionSort(arr6,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

int arr7[5] = {1,2,3,4,5};

int arr8[5] = {5,4,3,2,1};

int arr9[5] = {2,1,4,3,5};

compare=0;

swap =0;

printf(" SelectionSort ");

bubbleSort(arr7,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

selectionSort(arr8,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

compare=0;

swap=0;

selectionSort(arr9,5,&compare,&swap);

printf("compare : %d\tswap : %d ",compare,swap);

}

int bubbleSort(int a[], int n, int* ncompares_ptr, int* nswaps_ptr){

int i,j;

for( i=n-1;i>=0;i--){

for( j=0;j

(*ncompares_ptr)++;

if(a[j]>a[j+1]){

(*nswaps_ptr)++;

int temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

}

int insertionSort(int a[], int n, int* ncompares_ptr, int* nswaps_ptr){

int i;

for(i=1;i

int j=i-1,val=a[i];

while(j>=0&&a[j]>val) {

(*ncompares_ptr)++;

(*nswaps_ptr)++;

a[j+1]=a[j];

j--; }

a[++j]=val;

}

}

int selectionSort(int a[], int n , int* ncompares_ptr, int* nswaps_ptr){

int min,i,j;

for( i=0;i

min=i;

for( j=i+1;j

(*ncompares_ptr)++;

if(a[j]

if(min!=i){

(*nswaps_ptr)++;

int temp=a[i];

a[i]=a[min];

a[min]=temp;

}

}

}

I need a function

int insertionSort(int arr[], int size, int* ncompares_ptr, int* nshifts_ptr, int* nremovals_ptr, int* ninsertions_ptr); where arr[] is the integer array to sort, size is the number of elements in the array and ncompares__ptr, nswaps_ptr, nremovals_ptr, and ninsertions_ptr are pointers to int variables that will be written with the total number of compares performed, the total number of shifts performed, the total number of removals, and the total number of insertions to complete the sort. The function should return an integer containing the total number of steps (compares + shifts + removals + insertions) required to sort the array. NOTE: The parameters used to calculate efficiency in Insertion sorts are different than those of the bubble sort and selection sort.

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!