Insertion sort method in Single dimensional array

Insertion sort method is one of the must know the sorting algorithm for each and every computer science student.

In this sorting program, we are sorting an integer array of size 10 using the insertion sort method.  This method is sorting this array into ascending order.

Insertion sorting on a single dimensional array using functions.

/* Insertion sort algorithm
made by :rakesh kumar

using namespace std;

void output(int a[],int n){
for(int i=0;i<n;i++)

void input(int x[],int n){
for(int i=0;i<n;i++)
cout<<“Enter x[“<<i+1<<“] number : “;

void insertion_sort(int x[] ,int n)
int i,j,low,pos,temp;
for(i=1;i<n;i++) {
temp = x[i];
j= i-1;
while(temp<x[j] && j>=0){
j= j-1;

int main()
int x[10];
cout<<“\n sorted Array :”;
return 0;

Other most useful sorting algorithm are

  1. Bubble sort method program using single dimensional array
  2. selection sort method program using single dimensional array

If you need any other program on any sorting method, do post your request in comments.

Author: rakesh kumar is my online home, here I share all the information related to education, programming - and everything else that attract me. You can get in touch with me in these social sharing websites
Download File :

Leave a Reply