Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem : Introduction to selection sorting.
- // AUTHOR : fueanta
- // Written : 12-Oct-16
- #include "cstdio"
- #include "algorithm"
- using namespace std;
- void sel_sort(int *, int);
- void main() {
- int arr[] = { 5, 3, 7, 2, 4, 5, 1 }; /* just an example :p */
- printf("\n"); sel_sort(arr, (sizeof(arr) / 4));
- for (int i = 0; i < (sizeof(arr) / 4); i++) {
- printf("|%d|", arr[i]);
- }
- printf("\n\n");
- }
- void sel_sort(int arr[], int n) {
- for (int SELECT = 0; SELECT < n - 1; SELECT++) {
- int LOC = SELECT;
- for (int I = SELECT + 1; I < n; I++) {
- if (arr[I] < arr[LOC])
- LOC = I;
- }
- swap(arr[SELECT], arr[LOC]); // swap came from algorithm lib.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment