Sort the array's elements in increasing order
Here we will use Selection Sort like algorithm.
Arrays.sortarray;
The first for loop iterates all elements as elementi
for int i ; i size ; i
arrayi arrayi ;
arraysize ;
The second for loop finds the right position of elementi
for int j i ; j size; j
Compare ith value and jth value,
If arrayi arrayj swap these two values
if arrayi arrayj
For example, let arrayi arrayj to swap
arrayi and arrayj means arrayi will become
and arrayj will have
To swap the values in two positions, you would need an
extra variable to temporarily hold the value. For example,
temp arrayi;
arrayi arrayj;
arrayj temp;
int temp arrayi;
arrayi arrayj;
arrayj temp;