1 answer

Kindly help....use Github and gcc tool.....I always remember to give a thumbs up to correct answers...help...

Question:

Kindly help....use Github and gcc tool.....I always remember to give a thumbs up to correct answers...help Asap
github.com Part 3 (15 pts) - Write a C source code module called insertionsort.c that performs an Insertion sort on a fixed size array. Provide a header file (insertionsort.h) so that your insertion sort function can be called from an external program. Define a symbol called IS_VERBOSE and use conditional compilation (#ifdef.#endif) to enable and disable reporting of diagnostic information as the sort proceeds. You can model this information on the information about each passthrough that is present in the starter code (a working Bubble Sort program). insertionsort.c should implement a function with the following prototype: int insertionSort (int arrll, int size, int* ncompares_ptr, int* nswaps_ptr); where arr[l is the integer array to sort, size is the number of elements in the array and ncompares_ptr and nswaps_ptr are pointers to int variables that will be written with the total number of compares performed and the total number of swaps performed to complete the sort. The function should return an integer containing the total number of steps (compares swaps) required to sort the array.
github.com Part 3 (15 pts) - Write a C source code module called insertionsort.c that performs an Insertion sort on a fixed size array. Provide a header file (insertionsort.h) so that your insertion sort function can be called from an external program. Define a symbol called IS_VERBOSE and use conditional compilation (#ifdef.#endif) to enable and disable reporting of diagnostic information as the sort proceeds. You can model this information on the information about each passthrough that is present in the starter code (a working Bubble Sort program). insertionsort.c should implement a function with the following prototype: int insertionSort (int arrll, int size, int* ncompares_ptr, int* nswaps_ptr); where arr[l is the integer array to sort, size is the number of elements in the array and ncompares_ptr and nswaps_ptr are pointers to int variables that will be written with the total number of compares performed and the total number of swaps performed to complete the sort. The function should return an integer containing the total number of steps (compares swaps) required to sort the array.

Answers

//header file

#ifndef INSERTIONSORT_H
#define INSERTIONSORT_H
int insertionSort(int arr[],int size,int *ncompares_ptr,int *nswaps_ptr);
#endif

//c file

#include <stdio.h>

#include <math.h>

#include "insertionsort.h"//including header

// A utility function to print an array of size n

void printArray(int arr[], int n)

{

int i;

for (i=0; i < n; i++)

printf("%d ", arr[i]);

printf("\n");

}

  

/* Function to sort an array using insertion sort*/

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

{

int i, key, j;

int n=size;

for (i = 1; i < n; i++)

{

  

key = arr[i];

  

j = i-1;

/* Move elements of arr[0..i-1], that are

greater than key, to one position ahead

of their current position */

while (j >= 0 && arr[j] > key)

{

//incrementing number of comparisions and swaps

(*ncompares_ptr)++;

(*nswaps_ptr)++;

arr[j+1] = arr[j];

j = j-1;

}

arr[j+1] = key;

//printArray(arr, n);

  

}

  

//returning sum of comparision and swaps

return (*nswaps_ptr)+(*ncompares_ptr);

}

/* Driver program to test insertion sort */

int main()

{

int arr[] = {21,14,32,10,44,8,2,11,20,26};

int n = sizeof(arr)/sizeof(arr[0]);

printf("Array before sorting:\n");

printArray(arr, n);

int c=0,s=0;;

int sum = insertionSort(arr, n,&c,&s);

printf("Array after sorting:\n");

printArray(arr, n);

printf("Comparisions : %d\n Swaps : %d\n Sum : %d\n",c,s,sum);

return 0;

}

output:

Array before sorting:
21 14 32 10 44 8 2 11 20 26
Array after sorting:
2 8 10 11 14 20 21 26 32 44
Comparisions : 24
Swaps : 24
Sum : 48


Process exited normally.
Press any key to continue . . .

.

Similar Solved Questions

2 answers
Drawing a red checker from bag of 9 black checksrs and 6 red checkers, replacing it and drawing another red checker
drawing a red checker from bag of 9 black checksrs and 6 red checkers, replacing it and drawing another red checker...
1 answer
#8 Net income for 2020 reflects a total effective tax rate of 20%. Included in the...
#8 Net income for 2020 reflects a total effective tax rate of 20%. Included in the net income figure is a loss of $18,720,000 (before tax) as a result of a non-recurring major casualty. Preferred stock dividends of $374,400 were declared and paid in 2020. Dividends of $1,040,000 were declared and pa...
1 answer
Is a Lewis structure wrong if it doesn't show lone pairs?
Is a Lewis structure wrong if it doesn't show lone pairs?...
1 answer
Medicare for the aged and Medicaid for the medically indigent are considered what type of policy...
Medicare for the aged and Medicaid for the medically indigent are considered what type of policy objective? Economic efficiency Redistribution Reducing rising medical costs Reducing the number of uninsured...
1 answer
1. Discuss a kidney disorder. 2. What is the course of treatment for this disorder? 3....
1. Discuss a kidney disorder. 2. What is the course of treatment for this disorder? 3. What is the diet for this disorder? 4. Which lab values and/or electrolytes should be monitored in kidney disorders? 5. What is polysterene sulfonate?...
1 answer
Umassd.umassonline.net Blackboard Content - Blackboard Learn QuickLaunch - mums Take Test: Final Exam - ACT 211-710....
umassd.umassonline.net Blackboard Content - Blackboard Learn QuickLaunch - mums Take Test: Final Exam - ACT 211-710. Prin TRANSACTION ANALYS Remaining Time: 2 hours, 12 minutes, 52 seconds. Question Completion Status: QUESTION 18 10 points REPORTING PROPERTY, PLANT, and EQUIPMENT PROBLEM: The Bluebe...
1 answer
The current economy is strong and many people are feeling confident about their future and ability...
The current economy is strong and many people are feeling confident about their future and ability to pay off debt. Because of this they are taking on more bank loans for things like new cars, renovating their homes, or buying new homes Using the four step process with this type of market, what will...
1 answer
Explain why the CMS 1500 form is called the universal claim form...
explain why the CMS 1500 form is called the universal claim form......
1 answer
Understand the financial reporting environment. (Q1) List the 3 essential characteristics of FINANCIAL accounting & How...
Understand the financial reporting environment. (Q1) List the 3 essential characteristics of FINANCIAL accounting & How does it differ fromwith Managerial acct. (Q2) List the 4 financial statements typically provided: Q4. What is the objective of financial reporting? Q5 What does decision-useful...
1 answer
A very large nonconducting plate lying in the xy-plane carries a charge per unit area of...
A very large nonconducting plate lying in the xy-plane carries a charge per unit area of 50. A second such plate located at z = 2.25 cm and oriented parallel to the xy-plane carries a charge per unit area of -4o. Find the electric field for the following (a) z < 0 (b) 0 <z<2.25 cm 9/2 (c) z...
1 answer
Company X currently has annual sales of $10,000,000, its variable costs are 55% of sales and...
Company X currently has annual sales of $10,000,000, its variable costs are 55% of sales and total fixed costs $3,000,000. By how much will Company X's annual operating income increase if current sales increase by 12%?...
1 answer
Question Completion Status: Moving to another question will save this response. Question 25 Which of the...
Question Completion Status: Moving to another question will save this response. Question 25 Which of the following statements is False? When estimating the risk-free rate in the CAPM we should use the current yields on US Treasury securities Survey shows most large firms and financial analysts use t...
1 answer
Draw a schematic of the mechanism of the Latch Bridge for sustained smooth muscle contraction.
Draw a schematic of the mechanism of the Latch Bridge for sustained smooth muscle contraction....
1 answer
Answer both please Why does fluorenone travel more slowly than fluorene? Why does acetone speed up...
Answer both please Why does fluorenone travel more slowly than fluorene? Why does acetone speed up the rate at which fluorenone travels? (Make sure to include a picture of your TCL plate in your lab report)...
1 answer
Part V. Appropriations/Encumbrances/Expenditures The City of Arcadia Police Department gets an annual appropriation from the City...
Part V. Appropriations/Encumbrances/Expenditures The City of Arcadia Police Department gets an annual appropriation from the City for "Weapons and Miscellaneous" during 2013. Use encumbrances accounting. Prepare General fund journal entries to record the following transactions related to the...
1 answer
An object, previously at rest, slides #5 m# down a ramp, with an incline of #pi/8 #, and then slides horizontally on the floor for another #4 m#. If the ramp and floor are made of the same material, what is the material's kinetic friction coefficient?
An object, previously at rest, slides #5 m# down a ramp, with an incline of #pi/8 #, and then slides horizontally on the floor for another #4 m#. If the ramp and floor are made of the same material, what is the material's kinetic friction coefficient?...