- Olgoriths : This arrangement is highly classics
- Easy to learn and do
- speed is not optimal
- The idea: each turn one element selected element is pushed on the larger value before it until all properly sorted order.
#include 'stdio.h'
#include 'conio.h'
void selec(int arrnum[],int x,int y)
{
int temp;
temp=arrnum[x];
for(;x>y;x--) arrnum[x]=arrnum[x-1];
arrnum[x]=temp;
}
void main()
{
int i,j,a[10];
char flag;
for(i=0;i<10;i++) { printf("\na[%d]=",i);scanf("%d",&a[i]); } for(i=1;i<10;i++) for(j=0,flag='n';ja[i])
{
selec(a,i,j);
flag='y';
}
}
printf("\n Array before Sort : \n");
for(i=0;i<10;i++) printf("%d\t",a[i]);
getch();
}
No comments:
Post a Comment