Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
//Program to sort array using insertion sort
#include<iostream.h>
#include<limits.h>
void inssort(int[], int);
void main()...
Upcoming SlideShare
Loading in …5
×

Program to sort array using insertion sort

1,139 views

Published on

This is for the students of computer science for their projects

Published in: Education
  • Be the first to comment

  • Be the first to like this

Program to sort array using insertion sort

  1. 1. //Program to sort array using insertion sort #include<iostream.h> #include<limits.h> void inssort(int[], int); void main() { int ar[50], item, n, index; cout<<" How many elements do you want to create an array with? (max 50) "; cin>>n; cout<<"n Enter the array elements.."; for (int i=1; i<=n; i++) cin>>ar[i]; inssort(ar, n); cout<<"n The sorted array is as shown below"; for (int i=1; i<=n; i++) cout<<ar[i]<<" n"; } void inssort( int ar[], int size) { int tmp, j; ar[0]=IMI_MIN; for (int i=1; i<= size; i++) { tmp=ar[i]; j=i-1; while tmp<ar[j]; j--; } ar[j+1]=tmp; cout<< "array after pass "<< i <<" is "; for (int i=1; i<= size; i++) cout<< ar[k]<<" "; cout<<endl; } }

×