#include <stdio.h>
#define size 13
void main() { // take the array and sort it with insertion methods
	int  arr[size]={5,34,45,47,156,1,7,567,516,981,756,7,56} ;
	int i,j, val ;
	for(i=0;i<size;i++) printf("%d ",arr[i]);
	printf("Unsorted !!! \n");
	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("Sorted !!! \n");
}
Published in: C++
Download

Related snippets