INSERTION SORT

If you have any queries please leave a message here
Your Message
×


Insertion sort is based on the idea that one element from the input elements is consumed in each iteration to find its correct position i.e, the position to which it belongs in a sorted array.

It iterates the input elements by growing the sorted array at each iteration. It compares the current element with the largest value in the sorted array. If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position in the sorted array and moves it to that position. This is done by shifting all the elements, which are larger than the current element, in the sorted array to one position ahead.





Insertion Sort Programming in C

#include<stdio.h>
void main()
{
int a[]={ 80, 32, 28, 110, 50 };
int i, j, n;
for(i=1; i<5; i++)
{
j=(i-1);
n=a[i];
while(j >= 0 && a[j] > n)
{
a[j+1]=a[j];
j--;
}
a[j+1]=n;
}
for(i=0; i<5; i++)
{
printf("\t%d",a[i]);
}
}



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us