C&S 2024 Exam - Question 3 (b)

 avatar
itsLu
c_cpp
a year ago
336 B
3
Indexable
#include <iostream>
using namespace std;

void Insertion_Sort (int arr[], int n)
{
    int key, k, m;
    for (k = 0 ; k < n ; k++)
    {
        key = arr[k];
        m = k - 1;
        while (m >= 0 && arr[m] > key)
        {
            arr[m + 1] = arr[m];
            m--;
        }
        arr[m+1] = key;
    }
}
Editor is loading...
Leave a Comment