C language for Bubble sorting and Bubble Sorting
C language for Bubble Sorting
Algorithm Implementation:
# Include
# Include
Int main () {int arr [2] [3]; int I, j, k, temp; int * p = arr; printf ("\ n ======================== array initialization =========================\ n "); for (I = 0; I <2*3; I ++) {printf ("input element: \ n"); scanf ("% d ", p + I );} printf ("\ n ============================ start sort =====================\ n "); for (I = 0; I <2*3-1; I ++) {for (j = 0; j <(2*3-1)-I; j ++) {if (* (p + j)> * (p + j + 1) {temp = * (p + j + 1 ); * (p + j + 1) = * (p + j); * (p + j) = temp ;}} printf ("\ n ====================== % d times out ==================== ==\ n ", I + 1); for (k = 0; k <2*3; k ++) {printf ("% d", * (p + k ));}} printf ("\ n ================================================= \ n "); for (I = 0; I <2*3; I ++) {printf ("arr: % d \ n", * (p + I ));} return 0 ;}
The running result is as follows:
Bubble sort Demo:
Algorithm analysis:
Sorting Method |
Worst Time Analysis |
Average time complexity |
Stability |
Space complexity |
Bubble Sorting |
O (n2) |
O (n2) |
Stability |
O (1) |