Last active
December 29, 2020 10:51
-
-
Save ahmet-cetinkaya/207624b15eef03f7df14a7520a25408e to your computer and use it in GitHub Desktop.
Sort algorithms - Selection Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
main() | |
{ | |
int numbers[5] = { 10,1,53,5,8 }; | |
int length = sizeof(numbers) / sizeof(numbers[0]); | |
for (int i = 0; i < length; ++i) { | |
int minValueIndex = i; | |
for (int j = i; j < length; ++j) | |
if (numbers[j] < numbers[minValueIndex]) minValueIndex = j; | |
if (i != minValueIndex) { | |
int temp = numbers[i]; | |
numbers[i] = numbers[minValueIndex]; | |
numbers[minValueIndex] = temp; | |
} | |
} | |
for (const int& n : numbers) cout << n << " "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment