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
Get step-by-step solutions from verified subject matter experts
