September 9th, 2012, 05:31 AM
Hey buds.. I am newbie in C language programming.. I was writing a code for program featuring insertion sort.. Everything seems fine but I gut garbage values in the end instead of sorted values... Hope anyone can help debugging it... Whats the mistake in it..
printf("Number of Entries: ");
printf("Entry should not be greater than 10.\nRetry!\n");
printf("Entry should not be less than 2.\nRetry!\n");
while (n>10 || n<2);
September 9th, 2012, 06:46 AM
You need to be clear about which array elements you're using.
You read data in starting from element 1.
You start sorting at element 2.
Somehow, you involve the uninitialised element 0 in the actual sorting.
Your first correction would be to make both loops run as follows
for ( l = 0 ; l < n ; l++ )
By the way, main returns int, not void.
Success is indicated by having a return 0; at the end of main.
September 11th, 2012, 08:35 PM
Thanx bud for replying.. I have sorted out my mistake.. The problem was in the swapping code lines..
Comments on this post