コード例 #1
0
ファイル: Program.cs プロジェクト: pallavi-shah/Cities
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired

            // 1.To sort the list by CITY
            Console.WriteLine();
            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("** THE LIST ALPHABETICALLY SORTED BY CITY **");
            IComparer <City> comparer = new NameComparer();

            cities.Sort(comparer);

            PrintCities(cities);


            // 2.To sort the list by STATE
            Console.WriteLine();
            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("** THE LIST ALPHABETICALLY SORTED BY STATE **");

            IComparer <City> scomparer = new StateComparer();

            cities.Sort(scomparer);

            PrintCities(cities);


            // 3.To sort the list by POPULATION largest to smallest
            Console.WriteLine();
            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("** THE LIST SORTED BY POPULATION-LARGEST TO SMALLEST **");

            IComparer <City> pcomparer = new PopulationComparer();

            cities.Sort(pcomparer);
            cities.Reverse();
            PrintCities(cities);

            //BONUS MISSION- TO SORT FIRST BY STATE AND THEN BY POPULATION

            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("** THE LIST SORTED BY STATE AND THEN BY POPULATION **");
            CompoundComparer ccomparer = new CompoundComparer();

            ccomparer.Comparers.Add(new StateComparer());
            ccomparer.Comparers.Add(new PopulationComparer());
            cities.Sort(ccomparer);
            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired: Area  State  Population  Name
            IComparer <City> comparer = new NameComparer();

            cities.Sort(comparer);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired
            IComparer <City> comparer = new NameComparer();

            cities.Sort(comparer);

            PrintCities(cities);

            Console.ReadLine();


            IComparer <City> comparerState = new StateComparer();

            cities.Sort(comparerState);

            PrintCities(cities);

            Console.ReadLine();

            IComparer <City> comparerArea = new AreaComparer();

            cities.Sort(comparerArea);

            PrintCities(cities);

            Console.ReadLine();

            IComparer <City> comparerPopulation = new PopulationComparer();

            cities.Sort(comparerPopulation);

            PrintCities(cities);

            Console.ReadLine();

            CompoundComparer comparerCompound = new CompoundComparer();


            comparerCompound.Comparers.Add(new StateComparer());
            //cities.Sort(comparerCompound);
            comparerCompound.Comparers.Add(new PopulationComparer());
            //cities.Sort(comparerCompound);
            cities.Sort(comparerCompound);
            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired
            CompoundComparer comparer = new CompoundComparer();

            comparer.Comparers.Add(new StateComparer());
            comparer.Comparers.Add(new PopulationComparer());

            cities.Sort(comparer);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: InternDan/Cities-1
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired
            //IComparer<City> comparer = new PopulationComparer();
            MultiComparer multcomp = new MultiComparer();

            multcomp.Comparers.Add(new StateComparer());
            multcomp.Comparers.Add(new AreaComparer());

            cities.Sort(multcomp);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: mj-lang/Cities
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired
            IComparer <City> comparer  = new NameComparer();
            IComparer <City> statecomp = new StateComparer();
            IComparer <City> popcomp   = new PopulationComparer();
            IComparer <City> areacomp  = new AreaComparer();

            //cities.Sort(comparer);
            //cities.Sort(statecomp);
            //cities.Sort(popcomp);
            //cities.Sort(areacomp);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #7
0
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO Swap out comparers as desired
            IComparer <City> comparerN = new NameComparer();
            IComparer <City> comparerS = new StateComparer();
            IComparer <City> comparerA = new AreaComparer();
            IComparer <City> comparerP = new PopulationComparer();


            //cities.Sort(comparerN);
            //cities.Sort(comparerS);
            cities.Sort(comparerA);
            //cities.Sort(comparerP);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: jimflores5/Cities
        public static void Main(string[] args)
        {
            List <City>      cities = CityDataImporter.LoadData();
            IComparer <City> comparer;

            Console.WriteLine("Choose to sort by: \n" +
                              "1) City name \n" +
                              "2) State name \n" +
                              "3) Population \n" +
                              "4) Area");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                comparer = new NameComparer();
            }
            else if (choice == "2")
            {
                comparer = new StateComparer();
            }
            else if (choice == "3")
            {
                comparer = new PopulationComparer();
            }
            else
            {
                comparer = new AreaComparer();
            }

            // TODO Swap out comparers as desired
            //IComparer<City> comparer = new NameComparer();
            //IComparer<City> comparer = new StateComparer();
            //IComparer<City> comparer = new PopulationComparer();
            //IComparer<City> comparer = new AreaComparer();

            cities.Sort(comparer);

            PrintCities(cities);

            Console.ReadLine();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: wwohlschlaeger/Cities
        public static void Main(string[] args)
        {
            List <City>      cities             = CityDataImporter.LoadData();
            IComparer <City> comparerName       = new NameComparer();
            IComparer <City> comparerState      = new StateComparer();
            IComparer <City> comparerArea       = new AreaComparer();
            IComparer <City> comparerPopulation = new PopulationComparer();
            // TODO Swap out comparers as desired
            string choice;

            do
            {
                Console.WriteLine("Sort by (A)rea, (N)ame, (P)opulation, or (S)tate");
                choice = Console.ReadLine().ToLower();

                if (choice == "n" || choice == "name")
                {
                    cities.Sort(comparerName);
                }
                else if (choice == "a" || choice == "area")
                {
                    cities.Sort(comparerArea);
                }
                else if (choice == "s" || choice == "state")
                {
                    cities.Sort(comparerState);
                }
                else
                {
                    cities.Sort(comparerPopulation);
                }



                PrintCities(cities);

                Console.ReadLine();
            } while (choice != "");
        }
コード例 #10
0
        public static void Main(string[] args)
        {
            List <City> cities = CityDataImporter.LoadData();

            // TODO COMPLETE Swap out comparers as desired
            //IComparer<City> comparer = new NameComparer();
            //IComparer<City> comparer = new AreaComparer();
            //IComparer<City> comparer = new PopulationComparer();
            //IComparer<City> comparer = new StateComparer();

            CompoundComparer compoundComparer = new CompoundComparer();

            // by decending population - second sort key
            // within ascending state name - first sort key
            compoundComparer.Comparers.Add(new StateComparer());
            compoundComparer.Comparers.Add(new PopulationComparer());

            cities.Sort(compoundComparer);

            PrintCities(cities);

            Console.ReadLine();
        }