1. Bubble
Bubble is 1 2 3 4 5 6 7 8 9
2 1 3 4 5 6 7 8 9
2 3 1 4 5 6 7 8 9
2 3 4 1 5 6 7 8 9
2 3 4 5 1 6 7 8 9
.........
2 3 4 5 6 7 8 9 1
This is the first cycle.
9 8 7 6 5 4 3 2 1
The Code is as follows: This is a descending order. To increase the order, you only need to set if (a [J] <A [J + 1]) change to if (a [J]> A [J + 1])
For (INT I = 0; I "10; I ++)
For (Int J = 0; j <10-I-1; j ++ ){
If (A [J] <A [J + 1])
{
Int S = A [J] + A [J + 1];
A [J] = S-A [J];
A [J + 1] = S-A [J];
}
}
2. Select sort
1 2 3 4 5
2 1 3 4 5
3 1 2 4 5
4 1 2 3 5
5 1 2 3 4
This is to compare the first one with the subsequent one. A value is exchanged whenever the condition is not met.
Code
In ascending order, you only need to change if (a [I]> A [J]) to if (a [I] <A [J])
For (INT I = 0; I "10; I ++) // here 10 is the number of Arrays
For (Int J = 0; j <10; j ++) {// The number of 10 Arrays
If (A [I]> A [J])
{
Int S = A [I] + A [J];
A [I] = S-A [J];
A [J] = S-A [I];
}
}