After the video learning, summed up a bit, the great god please advise ....
If you want to arrange the numbers in the array in order from small to large.
Complete the idea: put the smallest number in the first item of the array, place the second small array in the second item, repeat it, and know it is done.
So how do you put the smallest number where the array index is 0?
Example:
for (int j = I+1;j < arrays. length;j++)
{
if (Arrays[0] > Arrays[j])
{
int temp = arrays[0];
Arrays[0] = Arrays[j];
ARRAYS[J] = temp;
}
}
Implementation method: The number of the first position is taken out and then compared to the number in the back position, if the number in the back position is large, then swap position.
Code Implementation Analysis: Repeated actions, if the index is 0 of the digital peso cited as the number of J large, then swap. The value range of J is 1-arrays. Length-1.
int i =? ;//array index bits currently being processed
for (int j = i + 1;j < arrays. length;j++)
{
if (Arrays[i] > Arrays[j])
{
int temp = Arrays[i];
Arrays[i] = Arrays[j];
ARRAYS[J] = temp;
}
}
Since 0 in the example is represented as an array index of the current processing, it is proposed to form a variable i, and the position of the variable J should begin with the next item in Index I.
Example: Use Exchange order to implement data arrays from small to large for type int:
for (int i = 0;i < arrays. Length-1; i++)
{
for (int j = i + 1;j < arrays. length;i++)
{
if (Arrays[i] > Arrays[j])
{
int temp = Arrays[i];
Arrays[i] = Arrays[j];
ARRAYS[J] = temp;
}
}
}
Similarly, an example of an array of type double arrays from small to large:
for (int i = 0;i < arrays. length-1;i++)
{
for (int j = i + 1;j < arrays. length;j++)
{
if (Arrays[i] < arrays[j])
{
Double temp = arrays[i];
Arrays[i] = Arrays[j];
ARRAYS[J] = temp;
}
}
}
Some of the above summarizes may be wrong, the gods have seen trouble to inform, grateful ...
How to arrange the numbers in the array in order from small to large???