#include <iostream>
int main()
{
const int nitems = 5;
int numbers[nitems];
int top;
int largest;
int tmp;
int i;
int j;
numbers[0] = 25;
numbers[1] = 1;
numbers[2] = 11;
numbers[3] = 18;
numbers[4] = -3;
cout << "\nHere is the unsorted array:\n");
for (i = 0; i < nitems; i++)
cout << "i is : " << i << "number is: "
<< numbers[i] << endl;
// Sort the array with a selection sort
top = 0;
for (top =0; top < (nitems -1); top++)
{
largest = top;
for (i = (top + 1); i < nitems; i++)
{
if (numbers[i] > numbers[largest])
largest = i;
}
// switch the 2 elements
tmp = numbers[largest];
numbers[largest] = numbers[top];
numbers[top] = tmp;
}
cout << "\nHere is the sorted array:\n");
for (i = 0; i < nitems; i++)
cout << "i is : " << i << "number is: "
<< numbers[i] << endl;
return(0);
}