Three basic sorting types (insert, bubble, select)
The insertion is stable. The bubble stability depends on whether there is an equal sign. The selection is unstable.
# Include
# Include
# Include
# Include
# Include
Using namespace std; void fun (); int main () {fun (); return 0;} void fun () {int temp, I, j, arr1 [8] = {19,1, 23,17, 19,55, 84,15}, arr2 [8] = {19,1, 23,17, 19,55, 84,15}, arr3 [8] = {19,1, 23,17, 19,55, 84,15}; // insert sort for (I = 1; I <8; I ++) {if (arr1 [I-1]> arr1 [I]) {temp = arr1 [I]; for (j = I-1; temp-1; -- j) arr1 [j + 1] = arr1 [j]; arr1 [j + 1] = temp ;}// Bubble Sorting for (int flag = 1, I = 1; I <8 & flag; ++ I) {for (flag = 0, j = 0; j <8-i; ++ j) {if (arr2 [j]> arr2 [j + 1]) {flag = 1; temp = arr2 [j + 1]; arr2 [j + 1] = arr2 [j]; arr2 [j] = temp ;}}// select sorting for (int flag, I = 0; I <8-1; I ++) {flag = I; for (j = I + 1; j <8; j ++) if (arr3 [j]
The result is as follows: