Monday, 16 February 2015

Write a Program in c++ for insertion sort algorithm

Structure of the Problem Requirements  

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quick sort, heap sort, or merge sort.

Source Code 

#include <iostream>
using namespace std;

int main()
cout<<"\n\n\t *************** INSERATION SORT ALGORITHM *****************\n\n\n";
int A[] = {31,41,59,26,42,58};
for(int j = 1,key,i; j<6; j++)
key = A[j];
i = j-1;
while(i>=0 and A[i]>key)
A[i+1] = A[i];
i = i-1;
A[i+1] = key;

for(int k=0; k<6; k++)
cout<<A[k]<<" "<<endl;
return 0;

Output of the Program

 insertion sort algorithm

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment