Answer to Question #283855 in C++ for tayyaba

Question #283855

Assume the following list of keys: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15


This list is to be sorted using insertion sort as described in this chapter for


array-based lists. Show the resulting list after six passes of the sorting


phase—that is, after six iterations of the for loop.

1
Expert's answer
2022-01-02T02:20:29-0500
C++
Q283855
 Deadline passed

Assume the following list of keys: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15




This list is to be sorted using insertion sort as described in this chapter for




array-based lists. Show the resulting list after six passes of the sorting




phase—that is, after six iterations of the for loop.

Needs fixes
$1
Archive 
Tasks & Questions are stored in archive for 14 days
C++
Q283855
 Deadline: 31.12.21, 10:30

Assume the following list of keys: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15




This list is to be sorted using insertion sort as described in this chapter for




array-based lists. Show the resulting list after six passes of the sorting




phase—that is, after six iterations of the for loop.

Posted 2 days ago
Your offer
$1
30.12.21
System
20:50

Offer $1 submitted

System
22:30
You are welcome to start working with the question.
31.12.21
You
10:10

// C++ program for insertion sort

#include <bits/stdc++.h>




using namespace std;

 

/* Function to sort an array using insertion sort*/




void insertionSort(int arr[], int n)

{




    int i, key, j;




    for (i = 1; i < n; i++)




    {




        key = arr[i];




        j = i - 1;

 




        /* Move elements of arr[0..i-1], that are




        greater than key, to one position ahead




        of their current position */




        while (j >= 0 && arr[j] > key)




        {




            arr[j + 1] = arr[j];




            j = j - 1;




        }




        arr[j + 1] = key;




    }

}

 

// A utility function to print an array of size n




void printArray(int arr[], int n)

{




    int i;




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




        cout << arr[i] << " ";




    cout << endl;

}

 

/* Driver code */




int main()

{










int arr[] = { 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15};

    int n = sizeof(arr) / sizeof(arr[0]);

 




    insertionSort(arr, n);




    printArray(arr, n);

 




    return 0;

}

 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog