for (int i = 0;i < arr.length;i++)
{
tmp = arr[i];
for (int j = 0;j < arr.length;j++)
{
if (i == j) continue;
int x = tmp.compareTo(arr[j]);
if (x < 0)
{
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
As you could say, in the inner loop, it compares with the node side by side and moves just one step.
Each time it will be launched from the index of the outer loop and again retrieved through the rest of the data.
It seems to be a bubble, but it is a strange tool.
source
share