Record the position of the maximum and minimum values, and then exchange with the head and tail
How to write only the largest and smallest?
Big brother upstairs, thank you in advance.
No bubble sorting is required. Just traverse twice, find the largest one the first time, swap with the first element, find the smallest the second time, and swap the last element,
It can also be traversed at once, two together
int mint=a[0],maxt = a[0];
for(int i = 0; i <sizeof(a)/sizeof(int); ++i)
{
if(maxt <a[i])
//.......;
if(mint> a[i])
//........;
}