#include <cstdlib>
#include <iostream>
using namespace std;
void swap (int a[], int i, int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
void selectionsort(int a[], int n){
int i,j,min;
for (i=0; i<n-1; i++)
{
min=1;
for (j=i+1; j<n; j++)
if (a[j]<a[min]) min=j;
swap (a,i,min);
}
}
int main(int argc, char *argv[])
{
int a[10];
int i,j,n=10;
for (i=0; i<n; i++)
{
a[i]=rand()%100;
cout<<a [i]<<" ";
}cout <<endl;
selectionsort(a,n);
for(i=0; i<n; i++)
{
cout<<a[i]<<" ";
}cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Админ Ээгий
rggrer
ReplyDeleteene yu bodoj bga kod we
ReplyDelete