Write a c++ program to print the insertion sort using array

Write a c++ program to print the insertion sort using array. This is basic set of sorting algorithm in C++ programming language. Insert the every new values in the sorting. This method is known as insertion sorting program.

#include <iostream>
using namespace std;
void array(int array[], int size) 
{
for (int i = 0; i < size; i++)
{
cout << array[i] << " ";
}
cout << endl;
}
void sort(int array[], int size) 
{
for (int step = 1; step < size; step++) 
{
int key = array[step];
int j = step - 1;
while (key < array[j] && j >= 0) 
{
array[j + 1] = array[j];
--j;
}
array[j + 1] = key;
}
}
int main() 
{
int data[] = {10,56,34,78,9};
int size = sizeof(data) / sizeof(data[0]);
sort(data, size);
cout << "After sorting\n";
array(data, size);
}

Output:

After sorting 9 10 34 56 78