-- --

Insertion Sort using C

This program represents the implementation of Insertion Sort using C language:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,t,i,j;
printf("\nEnter the no. of elements");
scanf("%d",&n);
printf("\nEnter the elements of array");
for(i=0;i<n;i++)
  scanf("%d",&a[i]);
for(i=1;i<n;i++)
{
t=a[i];
j=i-1;
while(t<a[j]&&j>=0)
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=t;
}
printf("Ascending order of sorted list is:");
for(i=0;i<n;i++)
  printf("\n%d",a[i]);
getch();
}

kaliadevansh has written 15 articles

3 thoughts on “Insertion Sort using C

  1. Pooja says:

    I feel that this code is a little difficult to understand for Beginners!
    I found this following code for Insertion Algorithm which I think is beneficial for programmers:

    #include

    void main()
    {
    int arr[20],k,i,j;
    int limit;
    printf("Enter Limit for Array:\t");
    scanf("%d",&limit);
    printf("\nEnter %d Elements in the Array\n",limit);
    for(i=0;i<limit;i++)
    {
    scanf("%d",&arr[i]);
    }
    for(i=1;i=0 && k<arr[j]; j--)
    {
    arr[j+1]=arr[j];
    }
    arr[j+1]=k;
    }
    printf("\nSorted ist:\n");
    for(i=0;i<limit;i++)
    {
    printf("%d\t",arr[i]);
    }
    printf("\n");
    }

    Source: http://www.codingalpha.com/insertion-sort-algorithm-in-c/

  2. Oka says:

    Good post right here. One thing I’d like to say is the fact that most professional doaimns consider the Bachelor’s Degree just as the entry level standard for an online certification. Though Associate Diplomas are a great way to start, completing your current Bachelors starts up many doors to various jobs, there are numerous internet Bachelor Course Programs available coming from institutions like The University of Phoenix, Intercontinental University Online and Kaplan. Another thing is that many brick and mortar institutions offer you Online variations of their qualifications but normally for a extensively higher amount of money than the providers that specialize in online course plans.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>