Crescator cu BubbleSort:
#include <iostream>
using namespace std;
int main()
{
int a[6]={5,2,9,1,8,6};
bool interschimbat;
do
{
interschimbat=1;
for (int i=0; i<6-1; i++)
{
if (a[i]>a[i+1])
{
a[i]=a[i]+a[i+1];
a[i+1]=a[i]-a[i+1];
a[i]=a[i]-a[i+1];
interschimbat = 0;
}
}
} while (interschimbat==0);
for (int i=0; i<6; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
Descrescator cu SelectSort:
#include <iostream>
using namespace std;
int main()
{
int a[6]={5,2,9,1,8,6}, aux;
for (int i=0; i<5; i++)
{
for (int j=i+1; j<6; j++)
{
if (a[i]<a[j])
{
aux=a[i];
a[i]=a[j];
a[j]=aux;
}
}
}
for (int i=0; i<6; i++)
cout << a[i] << " ";
cout << endl;
return 0;
}