Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Insertion Sort In C
WhatsApp
Shobana J
8y
19.6
k
0
2
25
Blog
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.
C
Insertion Sort
Up Next
Bubble Sort In C
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found