What's new

Closed How to set numbers in array from lowest to highest.

Status
Not open for further replies.
int a, b;
int temp;
int sortTheNumbers = len - 1;

for (a = 0; a < sortTheNumbers; ++a) {
for (b = 0; b < sortTheNumbers; ++b) {
if (array < array[b + 1]) {
temp = array;
array = array[b + 1];
array[b + 1] = temp;
}
}
}
 
int a, b;
int temp;
int sortTheNumbers = len - 1;

for (a = 0; a < sortTheNumbers; ++a) {
for (b = 0; b < sortTheNumbers; ++b) {
if (array < array[b + 1]) {
temp = array;
array = array[b + 1];
array[b + 1] = temp;
}
}
}
 
Tulad ng binanggit ni angelofmercy
// to sort in asc order
Collections.sort(yourList);
// then para mareverse ang order
Collections.reverse(yourList);

Or pwede ka nalang gumamit neto.
// sort in dsc order
Collections.sort(yourList,Collections.reverse());

Import mo lang java.util.Collections
Or incase gusto mo ng mas customize na sorting use Comparator. :)
 
Status
Not open for further replies.

Similar threads

Back
Top