Sortarea prin selecție

#include <iostream>
using namespace std;
int main()
{
 int v[100],n,i,Max,p,j;
 cin>>n;
 for(i=1;i<=n;++i) cin>>v[i];
 for(i=n;i>=2;–-i)
  {Max=v[1];p=1;
  for(j=1;j<=i;++j)
   {if (v[j]>Max){Max=v[j];p=j;}
   v[0]=v[i];v[i]=v[p];v[p]=v[0];}
  }
 for(i=1;i<=n;++i) cout<<v[i]<<" ";
 return 0;
 }
Advertisements