Created
October 23, 2018 08:24
-
-
Save YassineBajdou/1a2f7ce5a117263f44eed0694e3d3d08 to your computer and use it in GitHub Desktop.
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
void selection_sort (int A[ ], int n) { | |
// temporary variable to store the position of minimum element | |
int minimum; | |
// reduces the effective size of the array by one in each iteration. | |
for(int i = 0; i < n-1 ; i++) { | |
// assuming the first element to be the minimum of the unsorted array . | |
minimum = i ; | |
// gives the effective size of the unsorted array . | |
for(int j = i+1; j < n ; j++ ) { | |
if(A[ j ] < A[ minimum ]) { //finds the minimum element | |
minimum = j ; | |
} | |
} | |
// putting minimum element on its proper position. | |
swap ( A[ minimum ], A[ i ]) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment