//INSERTION SORT
#include
//#include
#include
main ()
{
int a[100], n, s[100], temp, j, i;
printf ("Enter the number of elements in the array(max no:=100)\n");
scanf ("%d", &n);
printf ("eneter the elements :");
for (i = 0; i < n; i++)
{
scanf ("%d", &a[i]);
}
s[0] = a[0];
for (i = 1; i < n; i++)
{
temp = a[i];
j = i - 1;
while ((s[j] > temp) && (j >= 0))
{
s[j + 1] = s[j];
j--;
}
s[j + 1] = temp;
}
printf ("the sorted array is:\n");
for (i = 0; i < n; i++)
{
printf ("\n");
printf ("%d", s[i]);
}
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment