Q:

C Program For Insertion Sort In Ascending Order

belongs to collection: Sorting C Programs

0

Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include
int main()
{
  int i,j,s,temp,a[20];

  printf("Enter total elements: ");
  scanf("%d",&s);

  printf("Enter %d elements: ",s);
  for(i=0;i      scanf("%d",&a[i]);

  for(i=1;i      temp=a[i];
      j=i-1;
      while((temp=0))
   {
      a[j+1]=a[j];
          j=j-1;
      }
      a[j+1]=temp;
  }

  printf("After sorting: ");
  for(i=0;i      printf(" %d",a[i]);

  return 0;
}

 

Output:

Enter total elements: 5

Enter 5 elements: 12

36

25

14

45

After sorting  :12 14 25 36 45

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program For QUICK Sort In Ascending Order... >>
<< C Program For Selection Sort In Ascending And Desc...