#include <stdio.h>

void selectionsort(int x[], int length);

int main(void){
	int x[5] = {5, 4, 2, 1, 3};

	selectionsort(x,5);

	int i = 0;
	for (i = 0; i < 5; i++){
		printf("%d ",x[i]);
	}

	return 0;
}

void selectionsort(int x[], int length){
	int j =0;
	int i = 0;

	//for each element in the array
	for (i = 0; i < length; i++){

		int biggestSubscript = i;

		//for each element past that element in the array
		for(j = i + 1; j < length; j++){
		
			//find the biggest number
			if (x[biggestSubscript] < x[j] ){
				biggestSubscript = j;
			}

		}

		//swap to put the element in its right place
		int temp;
		temp = x[biggestSubscript];
		x[biggestSubscript] = x[i];
		x[i] = temp;

	}
}
