🔒 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
  • 852
    Views
  • 6
    Participants
Last reply from:
nhidz13

Trending Topics

Online now

Members online
570
Guests online
1,847
Total visitors
2,417

Forum statistics

Threads
2,292,354
Posts
29,076,198
Members
1,210,299
Latest member
Sfrsfgasrgbde
Back
Top