TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Insertion Sort In C
Shobana J
Jul 19, 2016
19.3
k
0
2
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, you will learn about insertion sort in C.
insertion (1).zip
Introduction
In this blog, I am going to explain how to insert the sort. It is a simple sorting algorithm, which is relatively efficient for a small list.
Compared to Bubble sort, Insertion sort is more efficient, though it has more constraints.
Software Requirements
Turbo C++ or C.
Programming
#include < stdio.h >
int
main()
{
int
n, array[1000], c, d, t;
printf(
"Enter number of elements\n"
);
scanf(
"%d"
, & n);
printf(
"Enter %d integers\n"
, n);
for
(c = 0; c < n; c++)
{
scanf(
"%d"
, & array[c]);
}
for
(c = 1; c <= n - 1; c++)
{
d = c;
while
(d > 0 && array[d] < array[d - 1])
{
t = array[d];
array[d] = array[d - 1];
array[d - 1] = t;
d--;
}
}
printf(
"Sorted list in ascending order:\n"
);
for
(c = 0; c <= n - 1; c++)
{
printf(
"%d\n"
, array[c]);
}
return
0;
}
Explanation
In the programming mentioned above, it is clearly understood that it can be arranged in an ascending order and it can be more efficient compared to Bubble sort.
Output
Conclusion:
Thus, it can be executed and printed successfully.
Insertion Sort
C
Next Recommended Reading
Bubble Sort In C