Exemple #1
0
    public int CompareTo(object obj)
    {
        if (obj is Wechicle)
        {
            Wechicle wechicleToCompare = (Wechicle)obj;
            //if (this.speed < wechicleToCompare.speed)
            //{
            //    return -1;
            //}
            //else if (this.speed > wechicleToCompare.speed)
            //{
            //    return 1;
            //}
            //else
            //{
            //    return 0;
            //}

            return(this.speed.CompareTo(wechicleToCompare.speed));
        }
        else
        {
            //!ERROR!MESSAGE!
            Console.WriteLine("Object is not correct!!!");
            return(0);
        }
    }
Exemple #2
0
        static void Main(string[] args)
        {
            Wechicle Ferrary = new Wechicle();
            Wechicle Zapor   = new Wechicle("Yellow", 66, 20, false, true);
            Wechicle Honda   = new Wechicle("White", 200);
            Wechicle Lada    = new Wechicle("Violet", 90, 60, false, false);
            Wechicle Tesla   = new Wechicle("Navi Blue", 100);

            Wechicle[] car = new Wechicle[5];
            car[0] = Ferrary;
            car[1] = Tesla;
            car[2] = Honda;
            car[3] = Lada;
            car[4] = Zapor;

            BubbleSorter <Wechicle> CarSorter = new BubbleSorter <Wechicle>();

            Wechicle[] sortedCars = CarSorter.Sort(car);
            CarSorter.Print(sortedCars);
            Console.WriteLine("Sorted by bubble, press any  key to continue");
            Console.ReadKey();
            Console.WriteLine("Now sorting by insertion");

            //Wechicle[] car = new Wechicle[5];
            car[1] = Ferrary;
            car[3] = Tesla;
            car[0] = Honda;
            car[2] = Lada;
            car[4] = Zapor;

            insertionSorter <Wechicle> CarInSorter = new insertionSorter <Wechicle>();

            sortedCars = CarInSorter.Sort(car);
            CarInSorter.Print(sortedCars);

            Console.ReadKey();
        }