Пример #1
0
        public static void Main()
        {
            Console.WriteLine("    Перечень фигур:\n");
            Rectangle rect   = new Rectangle(10, 20);
            Square    sq     = new Square(10);
            Circle    circle = new Circle(25);

            rect.Print();
            sq.Print();
            circle.Print();

            Console.WriteLine("\n    Коллекция ArrayList до сортировки:\n");
            ArrayList arrayListFigures = new ArrayList();

            arrayListFigures.Add(rect);
            arrayListFigures.Add(sq);
            arrayListFigures.Add(circle);
            foreach (GeomFig x in arrayListFigures)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("\n    После сортировки:\n");
            arrayListFigures.Sort();
            foreach (GeomFig x in arrayListFigures)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\n    Коллекция List<GeomFig> до сортировки:\n");
            List <GeomFig> fl = new List <GeomFig>();

            fl.Add(circle);
            fl.Add(rect);
            fl.Add(sq);
            fl.Sort();
            foreach (GeomFig x in fl)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("\n    После сортировки:\n");
            foreach (GeomFig x in fl)
            {
                Console.WriteLine(x);
            }

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

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

            Console.WriteLine("\n    Пример работы класса  SimpleStack:\n");
            Console.WriteLine("Фигуры добавлены в SimpleStack с помощью метода Push() и выведены с помощью метода Pop()\n");
            SimpleStack <GeomFig> simpleStackFigures = new SimpleStack <GeomFig>();

            simpleStackFigures.Push(rect);
            simpleStackFigures.Push(sq);
            simpleStackFigures.Push(circle);
            while (simpleStackFigures.Count != 0)
            {
                Console.WriteLine(simpleStackFigures.Pop());
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Rect   rect   = new Rect(6, 4);
            Square square = new Square(5);
            Circle circle = new Circle(7);

            // ArrayList

            Console.WriteLine("\nArrayList");
            ArrayList arrayList = new ArrayList();

            arrayList.Add(circle);
            arrayList.Add(rect);
            arrayList.Add(square);

            foreach (var x in arrayList)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nArrayList - отсортированный");
            arrayList.Sort();

            foreach (var x in arrayList)
            {
                Console.WriteLine(x);
            }

            // List<Figure>

            Console.WriteLine("\nList<AbstractFigure>");
            List <AbstractFigure> figureList = new List <AbstractFigure>();

            figureList.Add(circle);
            figureList.Add(rect);
            figureList.Add(square);

            foreach (var x in figureList)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nList<AbstractFigure> - отсортированный");
            arrayList.Sort();

            foreach (var x in arrayList)
            {
                Console.WriteLine(x);
            }

            // Matrix<Figure>

            Console.WriteLine("\nMatrix<AbstractFigure>");
            Matrix <AbstractFigure> matrix = new Matrix <AbstractFigure>(2, 2, 2, rect);

            Console.WriteLine(matrix.ToString());

            // SimpleList<AbstractFigure>

            Console.WriteLine("SimpleList<AbstractFigure>");
            SimpleList <AbstractFigure> list = new SimpleList <AbstractFigure>();

            list.Add(square);
            list.Add(rect);
            list.Add(circle);

            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine("\nSimpleList<AbstractFigure> - отсортированный");
            list.Sort();

            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            // SimpleStack<AbstractFigure>

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

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

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

            Console.ReadKey();
        }