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

This is in C Programming (not C++) , the problem below iam stuck on, Thank you i

ID: 3539997 • Letter: T

Question

This is in C Programming (not C++) , the problem below iam stuck on, Thank you in advance!


I am just typing this incase you cant see the picture very well, but the problem Iam stuck on is the picture.


49. Rewrite the straight insertion sort from chapter 8 using pointer arithmetic. The data to be sorted are to be read from a file. The array is to be dynamically allocated in the heap after reading the file to determine the number of elements. While reading the data to determine the size of array you will require, print them 10 integers to a line. Use the test data shown below.




The data will be sorted as they are read into the array. Do not fill the array and then sort the data. after the array has been sorted, print the data again using the same format you used for the unsorted.

Explanation / Answer

check it file location in D://




#include <cstdlib>

#include <iostream>

#include <fstream>

using namespace std;

void insertionSort(int arr[],int length);

int main(int argc, char *argv[])

{

ifstream inFile;



int status,i=0;

int b[100];

inFile.open("D:\abc.txt");

while(inFile)

{

inFile >> status;

b[i]=status;

i++;

}

i--;

insertionSort(b,i);

system("PAUSE");

return EXIT_SUCCESS;

}


void insertionSort(int arr[], int length) {

int i, j, tmp;

for (i = 1; i < length; i++) {

j = i;

while (j > 0 && arr[j - 1] > arr[j]) {

tmp = arr[j];

arr[j] = arr[j - 1];

arr[j - 1] = tmp;

j--;

}

}


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

cout<<arr[i];

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote