I need to create a method to sort an Object Array. I've never done this, but I must revise this for my course. I'm totally lost when it comes to implementing a sorting method. I need to sort using a insertion sort and selection sort.
This is my code I have so far in. All I must do is call the sort() when the user wishes to do so.
package citylisttest;
public class CityList {
private City[] city;
private Integer numberOfCities;
public CityList (Integer cityListSize){
this.city=new City[cityListSize];
this.numberOfCities=0;
}
public void addCity(String city){
this.city[this.numberOfCities]=new City(city);
this.numberOfCities++;
}
public String toString(){
String cityDetails=new String();
if (this.numberOfCities!=0){
cityDetails+=String.format("%-15s\n","CITY");
for(Integer i=0;i<this.numberOfCities;i++) {
cityDetails+=this.city[i]+"\n"; }
}
else
cityDetails+="City list is empty";
return cityDetails;
}
public void sort(){
}
}