Hi,
I'm having a problem while sorting the values using the selection sort and inserion sort alogos. Please someone tell me where I'm mistaking...?
Here's the code for selection sort:
and here's the code for insertion sort:Code:#include<stdio.h> #include<conio.h> void main (void) { clrscr(); int array[10],x,y; for (x=0;x<=9;x++) { printf("Enter Number: "); scanf("%d",&array[x]); } for(x=0;x<10;x++) { int i = x; for(int y=x; y<10; y++) { if(array[i]<array[y]) { i=y; } } int t=array[x]; array[x]=array[i]; array[i]=t; } printf ("\nAFTER SELECTION SORTING"); printf ("\n***** ********* *******"); for (x=0;x<=9;x++) { printf("\n%d",&array[x]); } getch(); }
Sorry for disturbing you guys with such basic things. Please reply me as soon as possible.Code:#include<stdio.h> #include<conio.h> void main(void) { int array[10],x,y,z=0; clrscr(); for (x=0;y<=9;y++) { printf("ENTER NUMBER: "); scanf("%d",&array[x]); } for (x=0;x<=9;x++) { if (array[0]>array[x]) { z=array[x]; array[x]=array[y]; array[y]=z; for (y=x;y<=0;y--) { array[y]=array[y-1]; } array[0]=z; } } printf ("\nAFTER INSERTION SORTING"); printf ("\n****** ********************"); for (x=0;x<=9;x++) { printf("\n\t%d",array[x]); } getch(); }
Thanks.



LinkBack URL
About LinkBacks


