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

Trending Topics

Online now

Members online
1,116
Guests online
3,912
Total visitors
5,028

Forum statistics

Threads
2,306,429
Posts
29,171,651
Members
1,194,814
Latest member
jasperboy123456
Back
Top