i have written a code for insertion sort but it is nt sorting.. kindly help me out in making the desired changes to mycode. thanx
#include<stdio.h>
int compare(int a,int b)
{
if(a>b)
return 1;
else if( a<b)
return -1;
else if(a==b)
return 0;
}
void insert(int m, int ms[], int size)
{
int j,k;
for (j=0; j<size; j++) // Find the right position
{ if (compare(m, ms[j])) break;
// Assertion: j is the right position for m
for (k=size-1; k>=j; k--) // Right shift values>m
ms[k+1] = ms[k];
ms[j] = m; } // Insert m
}
void insertSort(int ms[], int size)
{
int j;
// Loop Invariant:
// The sublist from ms[0] to ms[j-1] is sorted
for (j=1; j<size; j++) {
insert(ms[j], ms, j);
}
}
void main()
{
int i,arr[5]={55,66,22,44,39};
printf("sorting\n");
insertSort(arr,5);
for( i=0;i<5;i++)
{
printf("\n%d",arr[i]);
}
}
this is my xact code.. i have to use the two functions insert and insert sort!