Re: Sort Method Conversion
- From: hiwa <HGA03630@xxxxxxxxxxx>
- Date: Wed, 27 Jun 2007 19:48:21 -0700
On Jun 28, 9:07 am, kaltizer <kevinalti...@xxxxxxxxx> wrote:
I need to modify this method to sort an array of strings rather than
chars:
// selectionSort(): sorts the elements of a
public static void selectionSort(char[] v) {
for (int i = 0; i < v.length-1; ++i) {
// guess the location of the ith smallest element
int guess = i;
for (int j = i+1; j < v.length; ++j) {
if (v[j] < v[guess]) { // is guess ok?
// update guess to index of smaller element
guess = j;
}
}
// guess is now correct, so swap elements
char rmbr = v[i];
v[i] = v[guess];
v[guess] = rmbr;
}
}
}
Any ideas?
You could use String.compareTo() method for string comparison, instead
of < operatot.
.
- References:
- Sort Method Conversion
- From: kaltizer
- Sort Method Conversion
- Prev by Date: Re: double with precision
- Next by Date: Help with XML processing using DOM
- Previous by thread: Sort Method Conversion
- Next by thread: Re: Sort Method Conversion
- Index(es):
Relevant Pages
|