Insertion sort in data strcuture by R4R Team


program-

#include < stdio.h>
int main()
{
int n, array[1000], c, d, t;

printf("Enter number of elements\n");
scanf("%d", &n);

printf("Enter %d integersn", \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-1] > array[d]) {
t = array[d];
array[d] = array[d-1];
array[d-1] = t;

d--;
}
}

printf("After Sorting\n");

for (c = 0; c < = n - 1; c++) {
printf("%dn", array[c]);
}

return 0;
}


output-

Enter number of element
7
Enter 7 integers
3 1 5 2 6 7 9
After Sorting
1 2 3 5 6 7 9




Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!