#include<stdio.h>
int max(int a[],int len)
{
int maxid=0;
int i=1;
for(;i<len;i++ )
{
if(a[i]>a[maxid])
{
maxid=i;
}
}
return maxid; //return the subscript what represents the max number of a[]
}
int main()
{
int a[]={0,1,2,5,6,4,2,36,58,4,1,57,21};
int len=sizeof(a)/sizeof(a[0]);
int i=len-1;
for(;i>0;i--)
{
int maxid=max(a,i+1);
//swap a[maxid],a[len-1]
int t=a[maxid];
a[maxid]=a[i];
a[i]=t; // Swap the max number with the last subscript
}
int j=0;
for(;j<len;j++)
{
printf("%d ",a[j]);
}
// printf("%d\n",maxid);
return 0;
}