コード例 #1
0
ファイル: GeometricalFigure.cs プロジェクト: tigblack/Labs
        public int CompareTo(object obj)
        {
            GeometricalFigure figure = (GeometricalFigure)obj;

            if (this.Area() < figure.Area())
            {
                return(-1);
            }

            else if (this.Area() == figure.Area())
            {
                return(0);
            }

            else
            {
                return(1);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Yury132/Lab
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(10, 5);
            Circle    circle    = new Circle(10);
            Square    square    = new Square(5);


            ArrayList f1 = new ArrayList();

            f1.Add(rectangle);
            f1.Add(square);
            f1.Add(circle);

            Console.WriteLine("\nСодержимое коллекции ArrayList: ");
            foreach (var x in f1)
            {
                Console.WriteLine(x.ToString());
            }

            for (int i = 0; i < 50; i++)
            {
                Console.Write("-");
            }
            //-------------------------------------------------------------------------------------

            Console.Write("\nКоллекция класса List<Figure>");
            List <GeometricalFigure> f2 = new List <GeometricalFigure>();

            f2.Add(circle);
            f2.Add(rectangle);
            f2.Add(square);

            Console.WriteLine("\nПеред сортировкой: ");
            foreach (var x in f2)
            {
                Console.WriteLine(x.ToString());
            }

            f2.Sort();
            Console.WriteLine("\nПосле сортировки: ");
            foreach (var x in f2)
            {
                Console.WriteLine(x.ToString());
            }

            for (int i = 0; i < 50; i++)
            {
                Console.Write("-");
            }
            //-------------------------------------------------------------------------------------

            Console.WriteLine("\nМатрица: ");
            Matrix <GeometricalFigure> matrix = new Matrix <GeometricalFigure>(3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0] = rectangle;
            matrix[1, 1] = square;
            matrix[2, 2] = circle;
            Console.WriteLine(matrix.ToString());

            for (int i = 0; i < 50; i++)
            {
                Console.Write("-");
            }
            Console.WriteLine("\n");
            //-------------------------------------------------------------------------------------


            Console.WriteLine("\nSimpleStack: ");
            SimpleStack <GeometricalFigure> stack = new SimpleStack <GeometricalFigure>();

            stack.Push(rectangle);
            stack.Push(square);
            stack.Push(circle);

            while (stack.Count > 0)
            {
                GeometricalFigure f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }