#include <iostream>
using namespace std;

const int LIMIT = 200;

void selectionSort(int[], int);
int inputArraySize(int); 
void inputArray(int[], int);
void printArray(int[], int);

int main() {

	int size = inputArraySize(LIMIT);

	int array[LIMIT];
	inputArray(array, size);
	selectionSort(array, size);
	printArray(array, size);

	return 0;	
}

int inputArraySize(int limit) {
	
	int size;
	do {
		cout << "Input number of elements [1, " << limit << "]: ";
		cin >> size;
	} while(size < 1 || size > limit);
	return size;
}

void inputArray(int array[], int size) {

	cout << "Input all the " << size << " elements:" << endl;
	for(int i = 0; i < size; ++i) {
		cin >> array[i];
	}

}

void selectionSort(int array[], int size) {

	for(int i = size - 1; i > 0; --i) {
		int maxIndex = 0;
		// finding the largest element
		for(int j = 1; j <= i; ++j) {
			if(array[maxIndex] < array[j]) {
				maxIndex = j;
			}
		}
		swap(array[maxIndex], array[i]);
	}
}

void printArray(int array[], int size) {

	for(int i = 0; i < size; ++i) {
		cout << array[i] << " ";
	}
	cout << endl;
}

