Sort stability: Difference between revisions
Content added Content deleted
Line 150: | Line 150: | ||
cn = new String[cityList.length]; |
cn = new String[cityList.length]; |
||
System.arraycopy(cityList, 0, cn, 0, cityList.length); |
System.arraycopy(cityList, 0, cn, 0, cityList.length); |
||
System.out.println(); |
System.out.println("\nBefore sort:"); |
||
System.out.println("Before sort:"); |
|||
for (String city : cn) { |
for (String city : cn) { |
||
System.out.println(city); |
System.out.println(city); |
||
} |
} |
||
Arrays.sort(cn, new CityComparator()); |
|||
Arrays.sort(cn, cCompNm |
|||
); |
|||
System.out.println(); |
System.out.println("\nAfter sort on city:"); |
||
System.out.println("After sort on city:"); |
|||
for (String city : cn) { |
for (String city : cn) { |
||
System.out.println(city); |
System.out.println(city); |
||
Line 168: | Line 164: | ||
cn = new String[cityList.length]; |
cn = new String[cityList.length]; |
||
System.arraycopy(cityList, 0, cn, 0, cityList.length); |
System.arraycopy(cityList, 0, cn, 0, cityList.length); |
||
System.out.println(); |
System.out.println("\nBefore sort:"); |
||
System.out.println("Before sort:"); |
|||
for (String city : cn) { |
for (String city : cn) { |
||
System.out.println(city); |
System.out.println(city); |
||
} |
} |
||
Arrays.sort(cn, new CountryComparator()); |
|||
Arrays.sort(cn, cCompCtry); |
|||
System.out.println(); |
System.out.println("\nAfter sort on country:"); |
||
System.out.println("After sort on country:"); |
|||
for (String city : cn) { |
for (String city : cn) { |
||
System.out.println(city); |
System.out.println(city); |