#include <stdio.h>

#define size 13
// take the array and sort it with insertion methods
void main()
{
	int  arr[size]={5,34,45,47,156,1,7,567,516,981,756,7,56} ;
    int i=0, j=0 , val ;

	for(i=1;i<size;i++)
	{
		val=arr[i] ;
		j=i;
		while( (j>0) && (arr[j-1]>val) )
		{ 
		  arr[j]=arr[j-1];
		  j-- ;
		}
		arr[j]=val;
	}
    for(i=0;i<size;i++)
		printf("%d ",arr[i]);
	printf("\n");
}
Published in: C++
Download

Related snippets