Jump to content

Sort stability: Difference between revisions

m
Line 150:
cn = new String[cityList.length];
System.arraycopy(cityList, 0, cn, 0, cityList.length);
System.out.println("\nBefore sort:");
System.out.println("Before sort:");
for (String city : cn) {
System.out.println(city);
}
 
Comparator<String> cCompNm =Arrays.sort(cn, new CityComparator());
Arrays.sort(cn, cCompNm
);
 
System.out.println("\nAfter sort on city:");
System.out.println("After sort on city:");
for (String city : cn) {
System.out.println(city);
Line 168 ⟶ 164:
cn = new String[cityList.length];
System.arraycopy(cityList, 0, cn, 0, cityList.length);
System.out.println("\nBefore sort:");
System.out.println("Before sort:");
for (String city : cn) {
System.out.println(city);
}
 
Comparator<String> cCompCtry =Arrays.sort(cn, new CountryComparator());
Arrays.sort(cn, cCompCtry);
 
System.out.println("\nAfter sort on country:");
System.out.println("After sort on country:");
for (String city : cn) {
System.out.println(city);
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.