Friday, 12 September 2014

SELECTION SORT

void max(int A[],int min,int max)
{
int large=A[min];
int i;
int pos=min;
for(i=min+1;i<=max;i++)
{
if(A[i]>large)
{
pos=i;
large=A[i];
}
}
if(pos==max)return;
A[pos]=A[pos]+A[max];
A[max]=A[pos]-A[max];
A[pos]=A[pos]-A[max];
}




main()
{
int A[]={22,1,55,4,33a};
int i=0;
int min=0;
while(i<4)
{
    max(A,min,4-i);
i++;
}
for(i=0;i<5;i++)
printf("%d\n",A[i]);
}

No comments:

Post a Comment