示例#1
0
        static void Main(string[] args)
        {
            Circle    a = new Circle(10);
            Rectangle b = new Rectangle(2, 5);
            Square    c = new Square(7);

            ArrayList list1 = new ArrayList();

            list1.Add(a);
            list1.Add(b);
            list1.Add(c);

            list1.Sort();

            foreach (Geometric_figures i in list1)
            {
                System.Console.WriteLine(i.ToString());
            }

            List <Geometric_figures> list2 = new List <Geometric_figures>();

            list2.Add(a);
            list2.Add(b);
            list2.Add(c);

            list2.Sort();

            System.Console.WriteLine();

            foreach (Geometric_figures i in list2)
            {
                System.Console.WriteLine(i.ToString());
            }

            System.Console.WriteLine();

            SparseMatrix.Matrix <Geometric_figures> matrix1 = new SparseMatrix.Matrix <Geometric_figures>(2, 2, 1, new Circle(0));
            matrix1[0, 0, 0] = new Circle(1);
            matrix1[1, 0, 0] = new Square(2);
            matrix1[1, 1, 0] = new Rectangle(1, 2);
            System.Console.WriteLine(matrix1.ToString());

            SimpleStack <Geometric_figures> SStack = new SimpleStack <Geometric_figures>();

            SStack.Add(a); SStack.Add(b); SStack.Add(c);
            SStack.Sort();

            for (int i = SStack.Count; i > 0; i--)
            {
                System.Console.WriteLine(SStack.Pop());
            }

            System.Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            Rectangle rect   = new Rectangle(30, 60);
            Square    sqr    = new Square(13);
            Circle    circle = new Circle(8);
            ArrayList list   = new ArrayList();

            list.Add(rect); list.Add(sqr); list.Add(circle);
            list.Sort();
            foreach (Figure obj in list)
            {
                System.Console.WriteLine(obj.GetType().Name);
                obj.Print();
            }
            Console.WriteLine("-------------------------------------------");
            List <Figure> list2 = new List <Figure>();

            list2.Add(rect); list2.Add(sqr); list2.Add(circle);
            list2.Sort();
            foreach (Figure obj in list2)
            {
                System.Console.WriteLine(obj.GetType().Name);
                obj.Print();
            }
            Console.WriteLine("-------------------------------------------");
            SparseMatrix.Matrix <Figure> drop = new SparseMatrix.Matrix <Figure>(2, 2, 1, new Circle(0));
            drop[0, 0, 0] = new Circle(1);
            drop[1, 0, 0] = new Square(2);
            drop[1, 1, 0] = new Rectangle(1, 2);
            System.Console.WriteLine(drop.ToString());
            Console.WriteLine("-------------------------------------------");
            SimpleStack <Figure> primer = new SimpleStack <Figure>();

            primer.Add(circle); primer.Add(rect); primer.Add(sqr);
            primer.Sort();

            for (int i = primer.Count; i > 0; i--)
            {
                System.Console.WriteLine(primer.Pop());
            }
            System.Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            // Объекты фигур
            Rectangle rec    = new Rectangle(4.5, 2);
            Square    sq     = new Square(3.14);
            Circle    circle = new Circle(1);

            // Проверка через ArrayList
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\t\tArrayList");
            Console.ForegroundColor = ConsoleColor.Gray;
            ArrayList alist = new ArrayList();

            alist.Add(sq);
            alist.Add(rec);
            alist.Add(circle);
            foreach (Figure item in alist)
            {
                Console.WriteLine(item);
            }
            alist.Sort();
            Console.WriteLine("\nПосле сортировки:\n");
            foreach (Figure item in alist)
            {
                Console.WriteLine(item);
            }

            // Проверка через List<>
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t\tList<Figure>");
            Console.ForegroundColor = ConsoleColor.Gray;
            List <Figure> list = new List <Figure>();

            list.Add(rec);
            list.Add(sq);
            list.Add(circle);
            foreach (Figure item in list)
            {
                Console.WriteLine(item);
            }
            list.Sort();
            Console.WriteLine("\nПосле сортировки:\n");
            foreach (Figure item in list)
            {
                Console.WriteLine(item);
            }

            // Проверка доработанной трехмерной матрицы
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t\tМатрица");
            Console.ForegroundColor = ConsoleColor.Gray;
            Matrix <Figure> matrix = new Matrix <Figure>(new FigureMatrixCheckEmpty(), 3, 3, 3);

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

            // Проверка SimpleStack
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t\tSimpleStack<Figure>");
            Console.ForegroundColor = ConsoleColor.Gray;
            SimpleStack <Figure> slist = new SimpleStack <Figure>();

            slist.Add(rec);
            slist.Add(sq);
            slist.Add(circle);
            foreach (Figure item in slist)
            {
                Console.WriteLine(item);
            }
            slist.Sort();
            Console.WriteLine("\nПосле сортировки:\n");
            foreach (Figure item in slist)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\n");
        }