Question: void insert(int arr[], int n) { for (int x = 1; x < n; x++){ bool done = false; for (int y = x; y
void insert(int arr[], int n) {
for (int x = 1; x < n; x++){
bool done = false;
for (int y = x; y > 0 && !done; y--) {
if (arr[y] < arr[y - 1]) {
swap(arr[y], arr[y - 1]);
cout << arr[y];
} else {
done = true;
}
}
}
}
C++. Modify and update the insertion sort function above to make a program that sorts an array from the end. Then show how many comparisons and how many swaps for each pass.
int array[] = {5, 6,9,10, 1};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
