±Û¾´ÀÌ :À̼ºÈÆ 1999³â 12¿ù 13ÀÏ 21:22:51
In Reply to: °¡¸£ÃÄÁÖ¼¼¿ë!! sorting method posted by ±èÁؼ® on 1999³â 12¿ù 11ÀÏ 00:50:43:
/*
ÁÁÀº ¼º´ÉÀÇ ¼ÒÆÃÀº ¾Æ´ÏÁö¸¸, ¹öºí ¼ÒÆà ¿¹Á¦°¡ ÀÖ¾î¼ ¿Ã·Áµå¸³´Ï´Ù.
Âü°í°¡ µÇ¼ÌÀ¸¸é ÁÁ°Ú³×¿ä.
Âü°íµµ¼´Â
Java Distributed Objects , SAMS - Bill McCarty and Luke Cassady-Dorion
ÀÔ´Ï´Ù.
*/
public class AlbumSorter {
/**
* Sorts, using the bubble sort, all AlbumI objects
* by artist name.
*/
public static void sortByArtistName(AlbumI[] albums) {
int iLength = albums.length;
iLength--;
boolean bSwapHappened = true;
while(bSwapHappened) {
bSwapHappened = false;
for(int i=0; i<iLength; i++) {
if(albums[i].sArtistName().charAt(0) > albums[i+1].sArtistName().charAt(0)) {
bSwapHappened = true;
AlbumI temp = albums[i];
albums[i] = albums[i+1];
albums[i+1] = temp;
}
}
}
}
/**
* Sorts, using the bubble sort, all AlbumI objects
* by album name.
*/
public static void sortByAlbumName(AlbumI[] albums) {
int iLength = albums.length;
iLength--;
boolean bSwapHappened = true;
while(bSwapHappened) {
bSwapHappened = false;
for(int i=0; i<iLength; i++) {
if(albums[i].sAlbumName().charAt(0) > albums[i+1].sAlbumName().charAt(0)) {
bSwapHappened = true;
AlbumI temp = albums[i];
albums[i] = albums[i+1];
albums[i+1] = temp;
}
}
}
}
}