🔒 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.

About this Thread

  • 7
    Replies
  • 832
    Views
  • 6
    Participants
Last reply from:
nhidz13

Online now

Members online
720
Guests online
646
Total visitors
1,366

Forum statistics

Threads
2,275,125
Posts
28,960,808
Members
1,232,631
Latest member
marlaa1991
Back
Top