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

Rewrite the straight insertion sort from chapter 8 using pointer arithmetic. The

ID: 3536536 • Letter: R

Question

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

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--;

            }

      }

}

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