Data Structure-selection and sorting using C language
Version 1: update immediately. Please wait ...... version 2: // select sorting // first set the 0 position as the index, and then use the index to find the smallest value. // put the smallest value in front of each row, then exchange the data with the original data location // Yang Xin # include
# Include
# Define MAXN 100int arr [MAXN]; void SelectionSort (int a [], int size) {int index = 0, I = 0, j = 0, temp = 0; for (I = 0; I <size; I ++) {index = I; for (j = I + 1; j <size; j ++) {if (arr [index]> arr [j]) {index = j ;}} if (index! = I) {temp = arr [I]; arr [I] = arr [index]; arr [index] = temp ;}} int main () {int I = 0; arr [0] = 44; arr [1] = 33; arr [2] = 55; arr [3] = 999; arr [4] = 42; printf (====================================================== ======== ); printf (the data order before sorting is 44 33 55 999 42); SelectionSort (arr, 5); printf (the sorted Data Order is :); for (I = 0; I <5; I ++) {printf (% d, arr [I]);} printf (====================================================== ======== ); return 0 ;}
Result: