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

t View Go Tools Window lp CSE30 lab4.pdf (page 4 of 4) (Exercise) create -sortAr

ID: 3668725 • Letter: T

Question

t View Go Tools Window lp CSE30 lab4.pdf (page 4 of 4) (Exercise) create -sortArray2.cpp In this part of the lab, your program will run similarly to sortArra However, the y1.cpp. sortArr function will use insertion sort algorithm instead of selection sort. Here is the descending of an insertion sort in ascending order, but you need to do both ascending and versions. Algorithm Insertionsort(A, n) A new array of n integers for i 1 to n-1 do saved Ali while j 0 AND ALi-11 saved do j j-1 end while A Lil save end for Before starting to write your program, use a piece of paper or a text editor to write the pseudocode of the sortArr function only. Remember to write the pseudocode for both ascending and descending versions. You will need to submit the pseudocode in order to receive full credit. Again there is no unique way to write pseudocode. It will be good

Explanation / Answer

void insertionSort(int array[], int size) {

   for (int i = 0; i < size - 1; i++) {

   int j = i + 1;

   int tmp = array[j];

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

    array[j] = array[j-1];

    j--;

    }

    array[j] = tmp;

    }

    }