Question: Complete the insertion sort algorithm to sort an array of numbers. #include using namespace std; void InsertionSort(int numbers[], int numbersSize) { /* write your code

Complete the insertion sort algorithm to sort an array of numbers.

#include

using namespace std;

void InsertionSort(int numbers[], int numbersSize) {

/* write your code here */

}

int main() {

int numbers[] = { 10, 2, 78, 4, 45, 32, 7, 11 };

const int NUMBERS_SIZE = 8;

int i;

cout << "Enter eight unsorted numbers: ";

for (i = 0; i < NUMBERS_SIZE; ++i) {

cin >> numbers[i];

}

cout << endl;

cout << "UNSORTED: ";

for (i = 0; i < NUMBERS_SIZE; ++i) {

cout << numbers[i] << ' ';

}

cout << endl;

InsertionSort(numbers, NUMBERS_SIZE);

cout << "SORTED: ";

for (i = 0; i < NUMBERS_SIZE; ++i) {

cout << numbers[i] << ' ';

}

cout << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!