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

Please help me, I need to have this done in c programming ( NOT C++) , using vis

ID: 3856748 • Letter: P

Question

Please help me, I need to have this done in c programming ( NOT C++), using visual studios 2015

Write a function called smallInt that takes in an array of integers and returns the smallest element in the array. Test your result with the array x = {23, 30, 19, 40, 3, 62, 4, 16, 2}.

- Given the following pseudo code for insertion sort. Write a corresponding function in C called insertionSort that fully implements the design efficiently.

PSEUDOCODE FOR INSERTION-SORT ALGORITHM

1. for j = 2 to n

2. key A [j]

3. // Insert A[j] into the sorted sequence A[1..j-1]. i.e. find the closest place to j to insert the key in the right order.

4. i j – 1

5. while i > 0 and A[i] > key

6. A[i+1] A[i]

7. i i – 1

8. A[i+1] key

Now sort the following arrays by calling the function insertionSort in the main function and passing the array.

Array A   

16 18 13 4 12 6

Array B

7 9 7 10 8 6

- Given the following pseudocode for selection sort. Write a corresponding function in C called selectionSort that fully implements the design efficiently.

PSEUDOCODE FOR SELECTION-SORT ALGORITHM

1. for j 1 to n-1

2. smallest j

3. for i j + 1 to n

4. if A[ i ] < A[ smallest ]

5. smallest i

6. Exchange A[ j ] A[ smallest ]

Now sort the following arrays by calling the function selectionSort in the main function and passing the array.

Array A

12 10 11 4 12 5

Array B

7 2 23 12 12 21

Explanation / Answer

int smallIndex () {
   int small = 0;
   for (int i =1; j<TUV300; j++)
       if (arr[i].key < arr[small].key)
           small = i;
   return small;
}

Here are the two sorting alorithms

void insertionSort(int* a; int n) {
   int i,j,key;
   for (i = 1; i < n; i++) {
       key = a[i];
       for (j = i-1; j >= 0; j--)
           if (a[j] > key)
               a[j+1] = a[j];
           else
               break;
       a[j+1] = key;
   }
}

void selectionSort(int* a; int n) {
   int i, j, smallest, tmp;
   for (i = 0; i < n-1; i++) {
       smallest = i;
       for (j = i+1; j < n ; j++)
           if (a[j] < a[smallest])
               smalles = j;
       if (smallest != i) {
           tmp = arr[i];
           arr[i] = arr[smallest];
           arr[smallest] = tmp;
       }
   }

}

I have not included the function call from main. I know you are smart enough to sove that. Let me know if you face any difficulty. Let me know if you need the function call from main()

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