Sort Method Conversion
- From: kaltizer <kevinaltizer@xxxxxxxxx>
- Date: Wed, 27 Jun 2007 17:07:36 -0700
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?
.
- Follow-Ups:
- Re: Sort Method Conversion
- From: Roedy Green
- Re: Sort Method Conversion
- From: hiwa
- Re: Sort Method Conversion
- Prev by Date: Re: double with precision
- Next by Date: Re: XML JDOM problems
- Previous by thread: double with precision
- Next by thread: Re: Sort Method Conversion
- Index(es):
Relevant Pages
|