I am trying to implement Bubble sort on a Countries Array in c#. My Country class is as shown below-
class Country {
private string name;
private string continent;
private long population;
public Country (string name, string continent, long population) {
this.name = name;
this.continent = continent;
this.population = population;
}
public static void BubbleSort(Country[] countryArray) {
Country temp;
int count = countryArray.Length;
for (int outer = 1; outer <= count; outer++)
{
for (int inner = 0; inner < outer - 1; inner++)
{ Country first = countryArray[inner];
Country second = countryArray[inner+1];
if (first.name > second.second)
{
temp = countryArray[inner];
countryArray[inner] = countryArray[inner + 1];
countryArray[inner + 1] = temp;
}
}
}
}
}
So, i know the code behind bubble sort. I just want it to work when user passes a comparer as an extra argument and even when user does not. Please help me.
I want my Bubble sort function to call like this-
Country.BubbleSort(countryArray, anyComparer());
EDIT: The Bubble sort method is a member function of Country class itself.