Select Sorting Algorithm and Sorting Algorithm
1. Select sorting
# Include <stdio. h> # include <stdlib. h> # define N 5 // Number of sorted data typedef struct Num {int data [N-1]; int length;} Num; int main (int argc, char * argv []) {int I, j, min; struct Num La; printf ("Enter the number sequence you want to sort: \ n"); for (I = 0; I <N; I ++) {scanf ("% d", & La. data [I]) ;}for (I = 0; I <N; I ++) {for (j = I; j <N; j ++) {int t; if (La. data [I]> = La. data [j]) {t = La. data [j]; La. data [j] = La. data [I]; La. data [I] = t ;}}} printf ("sorted numeric sequence: \ n"); for (I = 0; I <N; I ++) {printf ("% 3d", La. data [I]);} system ("pause"); return 0 ;}
Thought: Find the minimum values of all elements in each sort. First, select the smallest value and put it in the first position. Then, select the smallest value and put it in the second position, and so on.
The time complexity is O (n ^ 2)