Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # Implementation of Insertion Sort in C

• 0
• 2
• 2
• 0
• 0
• 0
• 0
• 0
• 316
Comment on it

Insertion Sort:- The Insertion sort is used to sort an array. The array can be sorted in each round means, In each Iteration of an array the element can be find in sorted.

Steps:-

1: The second element of array compared with the elements will appears before it . If the second element is smaller than first element, they both will interchange their positions. After first iteration, first two elements of an array will be sorted.

2. The third element of an array is compared with the elements that appears before it. If third element is smaller than first element, it is inserted in the position of first element. but in case If third element is larger than first element and smaller than second element, it is inserted in the position of second element. If third element is larger than both the elements, it is kept in the position as it is. After the completion of second iteration, first three elements of an array will be sorted.

```#include<stdio.h>
#include<conio.h>

void main()
{
int arr[10],i,j=0,temp=0;
clrscr();
printf("\nEnter 5 Elements in Array:=\n");
for(i=0;i<5;i++)
scanf("%d",&arr[i]);
for(i=1;i<5;i++)
{

temp=arr[i];
j=i-1;
while(temp<arr[j]&&j>=0)
{
arr[j+1]=arr[j];
j=j-1;
}

arr[j+1]=temp;
}
printf("\n\nSorted Array:=\n");
for(i=0;i<5;i++)
printf("\n%d",arr[i]);
getch();
}
```

## 0 Comment(s)

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General