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

Can someone please help me write a C program using insertion sort that reads in

ID: 3635684 • Letter: C

Question

Can someone please help me write a C program using insertion sort that reads in the first n numbers from a file that contains lots of integers and sorts them. The number n is given to your program via argv[1]. The name of the file of numbers is given in argv[2]. After your program is done sorting, it should output the first number and the last number of the sorted list.

Explanation / Answer

#include #include void insertionSort(int arr[], int n){ int i, j ; for(i=1; i = 0; --j) { if(arr[j]>temp) arr[j+1]=arr[j]; else break ; } arr[j+1] = temp ; } } int main(int argc, char *argv[]) { int i, n, *arr; FILE *fp; n = atoi(argv[1]); fp = fopen(argv[2],r); arr = (int *)malloc(n*sizeof(int)); i=0; while(fscanf("%d", arr[i++]); insertionSort(arr, n); printf("First number: %d ", arr[0]); printf("Last number: %d ", arr[n-1]); return 0; }