Total Pageviews

PROGRAMMING OF SORTING

PROGRAM OF INSERTION SORTING


 #include<stdio.h>
 #include<conio.h>
 void main()
 {
 int a[100],n,pos,sn,i,j,temp;
 clrscr();
 printf("\n\nEnter the size of list:");
 scanf("%d",&n);
 printf("\n\nEnter the elements of list :");
 for(i=0;i<n;i++)
 {
 scanf("%d",&a[i]);
 }
 printf("\n\nYour list");
 for(i=0;i<n;i++)
 {
 printf("\t%d",a[i]);
 }
  for(i=0;i<n-1;i++)
  {
  sn=a[i];
  for(j=i+1;j<n;j++)
  {
    if(a[j]<=sn)
    {
    sn=a[j];
    pos= j;
    }
    }
    temp=a[i];
    a[i]=a[pos];
    a[pos]=temp;
  }
  printf("\n\nSorted List:");
  for(i=0;i<n;i++)
  {
  printf("\t%d",a[i]);
  }
  getch();

No comments:

Post a Comment