Insertion Sort in C++
by Sandeep on July 20, 2009
Insertion sort is a simple sorting algorithm, a comparison sort in which the sorted array (or list) is built one entry at a time.
It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
Program:
#include < iostream.h >
#include < conio.h >
void sort(int * a) {
for (int j = 2; j < 10; j++) {
for (int k = 0; k < j; k++) {
if (a[j] < a[k]) {
int temp = a[k];
a[k] = a[j];
a[j] = temp;
}
}
}
for (int i = 0; i < 10; i++) {
cout << a[i] << “n”;
}
}
void main() {
clrscr();
int a[] = {
1, 4, 6, 8, 0, 9, 7, 5, 2, 3};
sort(a);
}
if you find any bug in the above program. let us know about it. Please post your complaint at pctech@gadgetcage.com.

You can read more about me here. You can follow him on: Facebook | Twitter | Google +.
If you like this post, you can follow us on Twitter.
Subscribe to GadgetCage Feeds via RSS or Email to get instant updates.
Sai Sandeep has written 370 awesome articles for us.