C Program To Implement The Insertion Sorting Using Linear Array:How will you sort your mark-sheet arranged in pile, according to marks obtained? Well very easy, a very practical approach is to first, compare first and second marks and put them in order or correct position by inserting, now take out third one and compare it with second and first and put it in right position. Now take out fourth and so on.
This approach of inserting element in a sorted list is called as Insertion sort. Here is Pseudocode:
ALGORITHM:-
step 1 : start
step 2 : Take Input in the Array
step 3 : if the first Element is already Sorted, stored in Subarray
step 4 : Again take the Next Element
step 5 : Compare with all Elements Present in the sorted Subarray
step 6 : Set all the Element in the Sorted Subarray the is greater then the value to be sorted
step 7 : Repeat all the step until all element is sorted
step 8 : Print the sorted element of the array
step 9 : Stop the Exceution of the array
PROGRAM CODE:-
#include<stdio.h>
#include<conio.h>
int main()
{
int array[1000],n,i;
printf("Enter the number of element: ");
scanf("%d",&n);
//Taking the Input of the array Element
printf("Enter Elements in the list : ");
for(i = 0; i < n; i++)
{
scanf("%d",&array[i]);
}
//Sorting of the array in Ascending order
for (i = 1; i < n; i++)
{
j = i;
while ( j > 0 && array[j] < array[j-1])
{
temp = array[j];
array[j] = array[j-1];
array[j-1] = temp;
j--;
}
}
//Sorted Array elements are
for(i = 0; i < n; i++ )
{
printf("%d\t",array[i]);
}
return 0;
}
OUTPUT:-
Enter the Number of Element: 5
Enter the Element in the Array
6 78 12 0 45
Element after sorting
0 6 12 45 78
Perform The Insertion Sort Using C How to Sort An Array Using Insertion Sorting Techique Sort the Array Element Using Insertion Sort in C
ConversionConversion EmoticonEmoticon