Example #1
0
        static void Main(string[] args)
        {
            square    s1   = new square(5);
            rectangle r1   = new rectangle(5, 6);
            rectangle r2   = new rectangle(6, 6);
            circle    c1   = new circle(5);
            ArrayList list = new ArrayList();

            list.Add(r1);
            list.Add(s1);
            list.Add(c1);
            foreach (var x in list)
            {
                Console.Write("{0} ", x);
            }
            list.Sort();
            Console.WriteLine("\nArray list after sorting");
            foreach (var x in list)
            {
                Console.Write("{0} ", x);
            }
            List <geom_shape> list1 = new List <geom_shape>();

            list1.Add(r1);
            list1.Add(s1);
            list1.Add(c1);
            Console.WriteLine("\nList before sorting");
            foreach (var x in list1)
            {
                Console.Write("{0} ", x);
            }
            list1.Sort();
            Console.WriteLine("\nList after sorting");
            foreach (var x in list1)
            {
                Console.Write("{0} ", x);
            }
            Console.WriteLine("");
            Matrix3dimensional <geom_shape> figure = new Matrix3dimensional <geom_shape>(4, 4, 4, null);

            figure[0, 0, 0] = r1;
            figure[1, 1, 1] = c1;
            figure[2, 2, 2] = s1;
            figure[1, 2, 3] = r2;
            Console.WriteLine(figure.ToString());
            SimpleStack <geom_shape> Stack = new SimpleStack <geom_shape>();

            Stack.Push(r1);
            Stack.Push(r2);
            Stack.Push(s1);
            Stack.Push(c1);
            while (Stack.Count > 0)
            {
                Console.WriteLine(Stack.Pop());
            }
            Console.ReadKey();
        }
Example #2
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();
        }
Example #3
0
        public static void Main()
        {
            Rectangle r    = new Rectangle(11, 13);
            Square    s    = new Square(11);
            Circle    c    = new Circle(11.13);
            ArrayList list = new ArrayList();

            list.Add(r);
            list.Add(s);
            list.Add(c);
            Console.WriteLine("Содержимое площади элементов коллекции ArrayList:");
            foreach (Figure f in list)
            {
                Console.WriteLine(f.GetArea());
            }
            List <Figure> listG = new List <Figure>();

            foreach (Figure f in list)
            {
                listG.Add(f);
            }
            listG.Sort();
            Console.WriteLine("Содержимое коллекции List<Figure>:");
            foreach (Figure f in listG)
            {
                Console.WriteLine(f.ToString());
            }
            Matrix <Figure> m = new Matrix <Figure>(1, 2, 3, new Square(0));

            m[0, 0, 0] = r;
            m[0, 1, 0] = new Rectangle(29, 11);
            m[0, 0, 1] = s;
            m[0, 1, 1] = new Square(29);
            m[0, 0, 2] = c;
            m[0, 1, 2] = new Circle(29.11);
            Console.WriteLine(m);
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Add(m[0, 0, 0]);
            stack.Pop();
            stack.Add(s);
            stack.Add(c);
        }
Example #4
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();
        }
Example #5
0
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle(5, 9);
            Square    s = new Square(10);
            Circle    c = new Circle(3);

            ArrayList aList = new ArrayList();

            aList.Add(r);
            aList.Add(s);
            aList.Add(c);

            Console.WriteLine("Array list before sorting");
            foreach (var x in aList)
            {
                Console.Write("{0} ", x);
            }
            aList.Sort();
            Console.WriteLine("\nArray list after sorting");
            foreach (var x in aList)
            {
                Console.Write("{0} ", x);
            }

            List <Figure> list = new List <Figure>();

            list.Add(r);
            list.Add(s);
            list.Add(c);

            Console.WriteLine("\nList before sorting");
            foreach (var x in list)
            {
                Console.Write("{0} ", x);
            }
            list.Sort();
            Console.WriteLine("\nList after sorting");
            foreach (var x in list)
            {
                Console.Write("{0} ", x);
            }

            SparseMatrix <Figure> matrix = new SparseMatrix <Figure>
                                               (3, 3, 3, new FigureSparseMatrixCheckEmpty());

            matrix[0, 0, 0] = r;
            matrix[1, 1, 1] = s;
            matrix[2, 2, 2] = c;
            Console.WriteLine(matrix.ToString());

            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(r);
            stack.Push(s);
            stack.Push(c);

            foreach (Figure f in stack)
            {
                Console.WriteLine(f);
            }

            Console.Read();
        }
        static void Main(string[] args)
        {
            Rectangle rec  = new Rectangle(4, 5);
            Square    sc   = new Square(5);
            Circle    cir  = new Circle(5);
            Circle    cir2 = new Circle(2);

            //*** Test 1: ArrayList ***
            ArrayList al = new ArrayList();

            al.Add(cir);
            al.Add(rec);
            al.Add(sc);
            al.Add(cir2);

            Console.WriteLine("Test 1: ArrayList");
            Console.WriteLine("\nДо сортировки:");
            foreach (Figure f in al)
            {
                Console.WriteLine(f);
            }
            al.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (Figure f in al)
            {
                Console.WriteLine(f);
            }

            //*** Test 2: List<T> ***
            List <Figure> list = new List <Figure>();

            list.Add(sc);
            list.Add(rec);
            list.Add(cir);
            list.Add(cir2);

            Console.WriteLine("\n\nTest 2: List<T>");
            Console.WriteLine("\nДо сортировки:");
            foreach (Figure f in list)
            {
                Console.WriteLine(f);
            }
            list.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (Figure f in list)
            {
                Console.WriteLine(f);
            }

            //*** Test 3: Matrix<T> ***
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rec;
            matrix[1, 1, 1] = sc;
            matrix[2, 2, 2] = cir;
            matrix[2, 0, 2] = cir2;
            Console.WriteLine("\n\nTest 3: Matrix<T>\n");
            Console.WriteLine(matrix.ToString());

            //*** Test 4: SimpleList<T> ***
            SimpleList <Figure> simple_list = new SimpleList <Figure>();

            simple_list.Add(cir);
            simple_list.Add(rec);
            simple_list.Add(cir2);
            simple_list.Add(sc);
            Console.WriteLine("Test 4: SimpleList<T>");
            Console.WriteLine("\nДо сортировки:");
            foreach (var x in simple_list)
            {
                Console.WriteLine(x);
            }
            simple_list.Sort();
            Console.WriteLine("\nПосле сортировки:");
            foreach (var x in simple_list)
            {
                Console.WriteLine(x);
            }

            //*** Test 5: SimpleStack<T> ***
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rec);
            stack.Push(sc);
            stack.Push(cir2);
            stack.Push(cir);
            Console.WriteLine("\nTest 5: SimpleStack<T>\n");
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }
Example #7
0
        static void Main(string[] args)
        {
            Rectangle rect   = new Rectangle(5, 4);
            Square    square = new Square(5);
            Circle    circle = new Circle(5);

            //коллекция класса ArrayList
            ArrayList figures = new ArrayList();

            figures.Add(circle);
            figures.Add(rect);
            figures.Add(square);
            Console.WriteLine("До сортировки для ArrayList");
            foreach (var i in figures)
            {
                Console.WriteLine(i);
            }
            figures.Sort();
            Console.WriteLine("\nПосле сортировки для ArrayList");
            foreach (var i in figures)
            {
                Console.WriteLine(i);
            }

            //коллекция класса List<Figure>
            List <Figure> figures1 = new List <Figure>();

            figures1.Add(circle); //добавление в коллекцию
            figures1.Add(rect);
            figures1.Add(square);
            Console.WriteLine("\n\nДо сортировки для List<Figure>:");
            foreach (var i in figures1)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("\nПосле сортировки для List<Figure>:");
            figures1.Sort();
            foreach (var i in figures1)
            {
                Console.WriteLine(i);
            }

            //создание разреженной матрицы
            Console.WriteLine("\n\nМатрица:");
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, new FigureMatrixCheckEmpty());

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

            //использование коллекции SimpleList
            SimpleList <Figure> list = new SimpleList <Figure>();

            list.Add(circle);
            list.Add(rect);
            list.Add(square);
            Console.WriteLine("\n\nПеред сортировкой (SimpleList):");
            foreach (var a in list)
            {
                Console.WriteLine(a);
            }
            list.Sort();
            Console.WriteLine("\n\nПосле сортировки (SimpleList):");
            foreach (var a in list)
            {
                Console.WriteLine(a);
            }

            //использование собственного стека
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(circle);
            stack.Push(rect);
            stack.Push(square);
            Console.WriteLine("\n\nИспользование стека:");
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }
Example #8
0
        static void Main(string[] args)
        {
            Rectangle rect   = new Rectangle(5, 4);
            Rectangle square = new Rectangle(5);
            Circle    circle = new Circle(5);

            rect.Print();
            square.Print();
            circle.Print();
            Console.ReadLine();
            ArrayList al = new ArrayList();

            //Добавление объектов в коллекцию
            al.Add(333);
            al.Add(123.123);
            al.Add("строка");
            al.Add(11);
            al.Add("q");
            al.Add(1456);
            al.Add(0.5);
            //Сортировка по типу данных
            foreach (object o in al)
            {
                string type = o.GetType().Name;
                if (type == "Int32")
                {
                    Console.WriteLine("Целое число: " + o.ToString());
                }
                else if (type == "String")
                {
                    Console.WriteLine("Строка: " + o.ToString());
                }
                else
                {
                    Console.WriteLine("Другой тип: " + o.ToString());
                }
            }

            Console.ReadLine();

            //Создание коллекции класса List<Figure>
            List <Figure> li = new List <Figure>();

            //Добавление объектов в коллекцию
            li.Add(rect);
            li.Add(square);
            li.Add(circle);
            //Сортировка по площади фигуры
            var orderedNumbers = from i in li
                                 orderby i.Area()
                                 select i;

            foreach (Figure i in orderedNumbers)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("\nМатрица");
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, 3, new FigureMatrixCheckEmpty());

            matrix[0, 0, 0] = rect;
            matrix[1, 1, 1] = square;
            matrix[2, 2, 2] = circle;
            Console.WriteLine(matrix.ToString());
            Console.ReadLine();
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            //добавление данных в стек
            stack.Push(rect);
            stack.Push(square);
            stack.Push(circle);
            //чтение данных из стека
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }
            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.Title = "Алпеев Владислав ИУ5-34Б";

            Circle cir = new Circle(5);

            cir.Print();
            Rectangle rect = new Rectangle(3, 6);   //экземпляры классов для коллекции

            rect.Print();
            Square sqr = new Square(2);

            sqr.Print();

            Console.WriteLine("\n\tArrayList");
            ArrayList Arr = new ArrayList();    //коллекция ArrayList

            Arr.Add(rect);
            Arr.Add(sqr);
            Arr.Add(cir);
            foreach (GeoFigure obj in Arr)
            {
                Console.WriteLine(obj.Area());
            }

            Console.WriteLine("\n\tList");
            List <GeoFigure> Lis = new List <GeoFigure>(); //коллекция класса List
            GeoFigure        buf;

            Lis.Add(rect);
            Lis.Add(sqr);
            Lis.Add(cir);
            for (int i = 0; i < Lis.Count; i++) //сортировка
            {
                for (int j = 0; j < (Lis.Count - (i + 1)); j++)
                {
                    if (Lis[j].CompareTo(Lis[j + 1]) == 1)
                    {
                        buf        = Lis[j];
                        Lis[j]     = Lis[j + 1];
                        Lis[j + 1] = buf;
                    }
                }
            }
            foreach (GeoFigure obj in Lis)
            {
                Console.WriteLine(obj.Area());
            }

            Console.WriteLine("\n\tMatrix");
            Matrix <GeoFigure> matr = new Matrix <GeoFigure>(3, 3, 3); //пример использования матрицы

            matr[1, 1, 0] = rect;
            matr[1, 1, 2] = sqr;
            matr[2, 2, 1] = cir;
            Console.WriteLine(matr.ToString());

            Console.WriteLine("\n\tSimpleStack");
            SimpleStack <GeoFigure> stack = new SimpleStack <GeoFigure>();

            stack.Push(rect);
            stack.Push(sqr);
            stack.Push(cir);
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());
            Console.WriteLine(stack.Pop());

            Console.ReadKey();
        }
Example #10
0
        static void Main(string[] args)
        {
            Console.Title = "Мирсонов Вячеслав РТ5-31Б";
            Rectangle rect   = new Rectangle(10, 5);   //объект класса Прямоугольник со сторонами 10 и 12
            Square    square = new Square(30);         //объект класса Квадрат со стороной 15
            Circle    circle = new Circle(10);         //объект класса Окружность с радиусом 10

            /*Необощенный список*/
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nКоллекция класса ArrayList");
            Console.ResetColor();
            ArrayList AL = new ArrayList();            //создане необобщенного списка

            /*добавление в необобщенный список рассматриваемых элементов*/
            AL.Add(circle);
            AL.Add(square);
            AL.Add(rect);
            /*вывод элементов необобщенного списка*/
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Необобщенный список:");
            Console.ResetColor();
            foreach (object o in AL)
            {
                Console.WriteLine(o.ToString());
            }

            /*Коллекция класса Figure*/
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nКоллекция класса List<Figure>");
            Console.ResetColor();
            List <Figure> LF = new List <Figure>();          // создане списка (коллекции класса Figure)

            /*добавление в список рассматриваемых элементов*/
            LF.Add(square);
            LF.Add(rect);
            LF.Add(circle);
            /*вывод элементов списка до сортировки*/
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Список до сортировки:");
            Console.ResetColor();
            foreach (var x in LF)
            {
                Console.WriteLine(x);
            }
            LF.Sort();            //сортировка
            /*вывод после сортировки*/
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nСписок после сортировки:");
            Console.ResetColor();
            foreach (var x in LF)
            {
                Console.WriteLine(x);
            }


            /*Односвязный список ListFigures*/
            SimpleList <Figure> OneCommunicationListFigures = new SimpleList <Figure>();          //создание односвязного списка

            /*добавление элементов в односвязный список*/
            OneCommunicationListFigures.Add(square);
            OneCommunicationListFigures.Add(circle);
            OneCommunicationListFigures.Add(rect);
            OneCommunicationListFigures.Sort();            //сортировка


            /*Трехмерная разреженная матрица*/
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nТрехмерная разреженная матрица");
            Console.ResetColor();
            Matrix3D <Figure> cube = new Matrix3D <Figure>(3, 3, 3, null);          //создание трехмерной разреженной матрицы 3х3х3 с передачей в качестве нулевого элемента - null

            /*доабвление отсортированных элементов списка OneCommunicationListFigures в словарь, создающий основу матрицы, на места на "главной диагонали"*/
            cube[0, 0, 0] = OneCommunicationListFigures.Get(0);
            cube[1, 1, 1] = OneCommunicationListFigures.Get(1);
            cube[2, 2, 2] = OneCommunicationListFigures.Get(2);
            Console.WriteLine(cube.ToString());
            Console.ResetColor();

            /*Реализация стека*/
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nСтек");
            Console.ResetColor();
            SimpleStack <Figure> SimpleFigureStack = new SimpleStack <Figure>();          //создание стека

            /*доабвление отсортированных элементов списка OneCommunicationListFigures в стек по прицнипу LIFO*/
            SimpleFigureStack.Push(OneCommunicationListFigures.Get(0));
            SimpleFigureStack.Push(OneCommunicationListFigures.Get(1));
            SimpleFigureStack.Push(OneCommunicationListFigures.Get(2));

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Реализация метода Pop() для стека SimpleFigureStack");
            Console.ResetColor();
            while (SimpleFigureStack.Count > 0)            //чтение из данных (элемента) с удалением из стека
            {
                Figure figur = SimpleFigureStack.Pop();
                Console.WriteLine(figur);
            }

            Console.ReadLine();
        }
Example #11
0
        static void Main(string[] args)
        {
            Console.Title = "Сахарова Елизавета ИУ5-32Б";

            Rectangle rectangle = new Rectangle(6, 4);
            Square    square    = new Square(5);
            Circle    circle    = new Circle(7);

            // ArrayList
            Console.WriteLine("ArrayList");
            ArrayList arrayList = new ArrayList();

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

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

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

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

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

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

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

            Console.WriteLine("\nОтсортированный List<Figure>");
            arrayList.Sort();

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

            // Matrix<Figure>
            Console.WriteLine("\nMatrix<Figure>");
            Matrix <Figure> matrix = new Matrix <Figure>(2, 2, 2, square);

            Console.WriteLine(matrix.ToString());

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

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

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

            Console.WriteLine("\nОтсортированный SimpleList<Figure>");
            list.Sort();

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

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

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

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

            Console.ReadKey();
        }
Example #12
0
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle(5, 4);

            Square square = new Square(5);

            Circle circle = new Circle(5);

            Console.WriteLine("\nArrayList");

            ArrayList al = new ArrayList();

            al.Add(circle);

            al.Add(rect);

            al.Add(square);

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

            Console.WriteLine("\nArrayList - сортировка");

            al.Sort();

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

            Console.WriteLine("\nList<Figure>");

            List <Figure> fl = new List <Figure>();

            fl.Add(circle);

            fl.Add(rect);

            fl.Add(square);

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

            Console.WriteLine("\nList<Figure> - сортировка");

            fl.Sort();

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

            Console.WriteLine("\nМатрица");

            Matrix <Figure> cube = new Matrix <Figure>(new FigureMatrixCheckEmpty(), 3, 3, 3);

            cube[0, 0, 0] = rect;

            cube[1, 1, 1] = square;

            cube[2, 2, 2] = circle;

            Console.WriteLine(cube.ToString());

            Console.WriteLine("\nСписок");

            SimpleList <Figure> list = new SimpleList <Figure>();

            list.Add(square);

            list.Add(rect);

            list.Add(circle);

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

            list.Sort();

            Console.WriteLine("\nСортировка списка");

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

            Console.WriteLine("\nСтек");

            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rect);

            stack.Push(square);

            stack.Push(circle);

            while (stack.Count > 0)
            {
                Figure f = stack.Pop();

                Console.WriteLine(f);
            }

            Console.ReadLine();
        }
Example #13
0
        static void Main(string[] args)
        {
            Console.Title = "Назаров Максим Михайлович Группа ИУ5-33Б";
            Rectangle rect = new Rectangle(8, 6);
            Square    sq   = new Square(8);
            Circle    cir  = new Circle(8);

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("\nArrayList");
            Console.ResetColor();
            ArrayList list = new ArrayList();

            list.Add(rect);
            list.Add(sq);
            list.Add(cir);
            foreach (var i in list)
            {
                Console.WriteLine(i.ToString() + " ");
            }

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

            list2.Add(rect);
            list2.Add(cir);
            list2.Add(sq);
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("\nПеред сортировкой:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }
            list2.Sort();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nПосле сортировки:");
            Console.ResetColor();
            foreach (var i in list2)
            {
                Console.Write(i.ToString() + " \n" + " ");
            }

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

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

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("\nСтек");
            Console.ResetColor();
            SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();

            stack.Push(rect);
            stack.Push(sq);
            stack.Push(cir);
            while (stack.Count > 0)
            {
                Geometric_figures f = stack.Pop();
                Console.WriteLine(f);
            }

            Console.ReadKey();
        }
Example #14
0
        static void Main(string[] args)
        {
            do
            {
                double[,] dimensions = new double[3, 2];
                string str; // временная сточная переменная для консольного ввода
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Лабораторная работа 3 - 'Cортировка геометрических фигур'");
                Console.Title = "Выполнил:Ли М.В. Группа:ИУ5-34Б";
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите длину Прямоугольника:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите ширину Прямоугольника:");
                double.TryParse(str, out dimensions[0, 0]);
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[0, 1]);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите длину стороны Квадрата:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[1, 0]);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.Write("Введите радиус Круга:");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                str = Console.ReadLine();
                Console.ResetColor();
                double.TryParse(str, out dimensions[2, 0]);
                Circle circle = new Circle(dimensions[2, 0]);
                circle.Print();
                Rectangle rectangle = new Rectangle(dimensions[0, 0], dimensions[0, 1]);
                rectangle.Print();
                Square square = new Square(dimensions[1, 0]);
                square.Print();

                Console.WriteLine("\n\tArrayList");
                ArrayList Arr = new ArrayList();
                Arr.Add(rectangle);
                Arr.Add(square);
                Arr.Add(circle);
                Console.WriteLine("\nИсходный ArrayList:", "DarkMagenta");
                foreach (var x in Arr)
                {
                    Console.WriteLine(x);
                }
                Arr.Sort();
                Console.WriteLine("\n\nОтсоритрованные ArrayList:", "DarkMagenta");
                foreach (var x in Arr)
                {
                    Console.WriteLine(x);
                }
                Console.WriteLine("\n\tList");
                List <GeomFigure> List = new List <GeomFigure>();
                GeomFigure        buf;
                List.Add(rectangle);
                List.Add(square);
                List.Add(circle);
                for (int i = 0; i < List.Count; i++)
                {
                    for (int j = 0; j < (List.Count - (i + 1)); j++)
                    {
                        if (List[j].CompareTo(List[j + 1]) == 1)
                        {
                            buf         = List[j];
                            List[j]     = List[j + 1];
                            List[j + 1] = buf;
                        }
                    }
                }
                Console.WriteLine("\nИсходный List:", "DarkMagenta");
                foreach (var x in List)
                {
                    Console.WriteLine(x);
                }
                List.Sort();
                Console.WriteLine("\nОтсортированный List:", "DarkMagenta");
                foreach (var x in List)
                {
                    Console.WriteLine(x);
                }
                Console.WriteLine("\n\tMatrix");
                Matrix <GeomFigure> matr = new Matrix <GeomFigure>(3, 3, 3);
                matr[1, 1, 0] = rectangle;
                matr[1, 1, 2] = square;
                matr[2, 2, 1] = circle;
                Console.WriteLine(matr.ToString());

                Console.WriteLine("\n\tSimpleStack");
                SimpleStack <GeomFigure> stack = new SimpleStack <GeomFigure>();
                stack.Push(rectangle);
                stack.Push(square);
                stack.Push(circle);
                Console.WriteLine(stack.Pop());
                Console.WriteLine(stack.Pop());
                Console.WriteLine(stack.Pop());
            } while (AskContinue());
        }
Example #15
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");
        }
Example #16
0
        static void Main(string[] args)
        {
            Rectangle rec1      = new Rectangle(2, 4);
            Square    sq1       = new Square(2);
            Circle    cir1      = new Circle(9);
            ArrayList arrayList = new ArrayList
            {
                rec1, sq1, cir1
            };

            Console.WriteLine("До сортировки");
            foreach (var i in arrayList)
            {
                Console.WriteLine(i);
            }

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


            List <GeomPhygure> geomPhygures = new List <GeomPhygure>();

            geomPhygures.Add(rec1);
            geomPhygures.Add(cir1);
            geomPhygures.Add(sq1);

            Console.WriteLine("\nДо сортировки");
            foreach (var i in geomPhygures)
            {
                Console.WriteLine(i);
            }

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


            Matrix <GeomPhygure> cube = new Matrix <GeomPhygure>(3, 3, 3, new FigureMatrixCheckEmpty());

            cube[0, 0, 0] = rec1;
            cube[1, 1, 1] = sq1;
            cube[2, 2, 2] = cir1;
            Console.WriteLine(cube.ToString());

            SimpleStack <GeomPhygure> stack = new SimpleStack <GeomPhygure>();

            stack.Push(rec1); stack.Push(sq1); stack.Push(cir1); //добавление данных в стек
            while (stack.Count > 0)                              //чтение данных из стека
            {
                GeomPhygure f = stack.Pop();
                Console.WriteLine(f);
            }


            Console.ReadLine();
        }
Example #17
0
        static void Main(string[] args)
        {
            double    a = 3, b = 4, r = 5;
            Rectangle rec  = new Rectangle(a, b);
            Square    sq   = new Square(a);
            Circle    circ = new Circle(r);

            ArrayList al = new ArrayList();

            al.Add(rec);
            al.Add(sq);
            al.Add(circ);
            al.Sort();
            Console.WriteLine("ArrayList");
            foreach (object obj in al)
            {
                Console.WriteLine(obj.ToString());                        //or through str type = obj.GetType().Name + ifs
            }
            Rectangle         rec2  = new Rectangle(4, 5);
            Square            sq2   = new Square(4);
            Circle            circ2 = new Circle(1);
            List <GeomFigure> list  = new List <GeomFigure>();

            list.Add(rec2);
            list.Add(sq2);
            list.Add(circ2);
            list.Sort();
            Console.WriteLine("\nList with " + list.Count() + " elements");
            foreach (GeomFigure figure in list)
            {
                Console.WriteLine(figure.ToString());
            }

            //----------------------------Sparse Matrix-----------------------------------
            Console.WriteLine("\nMatrix");
            Square nullFigure        = new Square(0);
            Matrix <GeomFigure> matr = new Matrix <GeomFigure>("matr", 3, 3, 3, nullFigure);

            matr[0, 0, 0] = rec;
            matr[1, 1, 1] = sq;
            matr[2, 2, 2] = circ;
            Console.WriteLine(matr.ToString());
            //---------------------------------------------------------------------------

            //---------------SimpleList-------------------------------------
            Console.WriteLine("\nSimpleList");
            SimpleList <GeomFigure> SimpleL = new SimpleList <GeomFigure>();

            SimpleL.AddElement(rec);
            SimpleL.AddElement(circ);
            SimpleL.AddElement(sq);
            foreach (var x in SimpleL)
            {
                Console.WriteLine(x);
            }
            //--------------------------------------------------------------

            //---------------SimpleStack-------------------------------------
            Console.WriteLine("\nSimpleStack");
            SimpleStack <GeomFigure> stack = new SimpleStack <GeomFigure>();

            stack.Push(rec);
            stack.Push(sq);
            stack.Push(sq);
            stack.Push(circ);
            foreach (var x in stack)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("\nStack Pop result: " + stack.Pop().ToString());
            Console.WriteLine("\nStack after Pop");
            foreach (var x in stack)
            {
                Console.WriteLine(x);
            }
            //--------------------------------------------------------------


            Console.ReadKey();
        }
Example #18
0
        static int Main(string[] args)
        {
            #region
            int       n    = 0;
            ArrayList arli = new ArrayList();
            List <Geometric_figures> li = new List <Geometric_figures>();

            double len;

            Rectangle rect = new Rectangle(0, 0);
            Console.WriteLine("Создание прямоугольника");
            Console.WriteLine("Введите значения:");
            Console.Write("Сторона: ");
            len          = Double.Parse(Console.ReadLine());
            rect.length1 = len;
            Console.Write("Сторона: ");
            len          = Double.Parse(Console.ReadLine());
            rect.length2 = len;

            Square scv = new Square(0);
            Console.WriteLine("Создание квадрата");
            Console.WriteLine("Введите значение");
            Console.Write("Сторона: ");
            len         = Double.Parse(Console.ReadLine());
            scv.length1 = len;
            scv.length2 = len;

            Console.WriteLine("Создание круга");
            Circle cir = new Circle(0);
            Console.WriteLine("Введите значение: ");
            Console.Write("Радиус: ");
            len        = Double.Parse(Console.ReadLine());
            cir.radius = len;

            arli.Add(rect);
            li.Add(rect);
            arli.Add(scv);
            li.Add(scv);
            arli.Add(cir);
            li.Add(cir);

            #endregion

            while (n != 5)
            {
                Main_menu();
                n = int.Parse(Console.ReadLine());
                switch (n)
                {
                case 1:
                {
                    int yeah;

                    Console.WriteLine("Как вы хотите отсортировать эту коллекцию?");
                    Console.WriteLine("  1. По возрастанию");
                    Console.WriteLine("  2. По убыванию");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 1)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 0)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }


                    Console.WriteLine();

                    foreach (object i in arli)
                    {
                        if (i.GetType().Name == "Прямоугольник")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Квадрат")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Круг")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 2:
                {
                    int yeah;

                    Console.WriteLine("Как вы хотите отсортировать эту коллекцию?");
                    Console.WriteLine("  1. По возрастанию");
                    Console.WriteLine("  2. По убыванию");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 0)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 1)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }

                    foreach (object i in li)
                    {
                        if (i.GetType().Name == "Прямоугольник")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Квадрат")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Круг")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 3:
                {
                    Console.WriteLine("\nMatrix");
                    Matrix <Geometric_figures> matrix = new Matrix <Geometric_figures>(3, 3, 3, new FigureMatrixCheckEmpty());
                    matrix[0, 0, 0] = rect;
                    matrix[1, 1, 1] = scv;
                    matrix[2, 2, 2] = cir;
                    Console.WriteLine(matrix.ToString());
                    break;
                }

                case 4:
                {
                    SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();
                    stack.Push(rect);
                    stack.Push(scv);
                    stack.Push(cir);

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

                case 5:
                {
                    Console.ReadKey();
                    break;
                }

                default:
                {
                    Console.WriteLine("Ошибка");
                }
                break;
                }
            }
            return(0);
        }
Example #19
0
        static int Main(string[] args)
        {
            #region
            int       n    = 0;
            ArrayList arli = new ArrayList();
            List <Geometric_figures> li = new List <Geometric_figures>();

            double len;

            Rectangle rect = new Rectangle(0, 0);
            Console.WriteLine("Creating rectangle");
            Console.WriteLine("Please put in your value");
            Console.Write("Length 1 ");
            len          = Double.Parse(Console.ReadLine());
            rect.length1 = len;
            Console.Write("Length 2 ");
            len          = Double.Parse(Console.ReadLine());
            rect.length2 = len;

            Square scv = new Square(0);
            Console.WriteLine("Please put in your value");
            Console.Write("Length ");
            len         = Double.Parse(Console.ReadLine());
            scv.length1 = len;
            scv.length2 = len;

            Circle cir = new Circle(0);
            Console.WriteLine("Please put in your value");
            Console.Write("Radius ");
            len        = Double.Parse(Console.ReadLine());
            cir.radius = len;

            arli.Add(rect);
            li.Add(rect);
            arli.Add(scv);
            li.Add(scv);
            arli.Add(cir);
            li.Add(cir);

            #endregion

            while (n != 5)
            {
                Main_menu();
                n = int.Parse(Console.ReadLine());
                switch (n)
                {
                case 1:
                {
                    int yeah;

                    Console.WriteLine("How do you want to sort this collection?");
                    Console.WriteLine("  1. Ascending");
                    Console.WriteLine("  2. Descending");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 1)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < arli.Count - 1; j++)
                        {
                            for (int i = 0; i < arli.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)arli[i]).CompareTo(arli[i + 1]) == 0)
                                {
                                    Object spec = arli[i];
                                    arli[i]     = arli[i + 1];
                                    arli[i + 1] = spec;
                                }
                            }
                        }
                    }


                    Console.WriteLine();

                    foreach (object i in arli)
                    {
                        if (i.GetType().Name == "Rectangle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Square")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Circle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 2:
                {
                    int yeah;

                    Console.WriteLine("How do you want to sort this collection?");
                    Console.WriteLine("  1. Ascending");
                    Console.WriteLine("  2. Descending");
                    yeah = int.Parse(Console.ReadLine());
                    if (yeah == 1)
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 0)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < li.Count - 1; j++)
                        {
                            for (int i = 0; i < li.Count - 1 - j; i++)
                            {
                                if (((Geometric_figures)li[i]).CompareTo(li[i + 1]) == 1)
                                {
                                    Object spec = li[i];
                                    li[i]     = li[i + 1];
                                    li[i + 1] = (Geometric_figures)spec;
                                }
                            }
                        }
                    }

                    foreach (object i in li)
                    {
                        if (i.GetType().Name == "Rectangle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Rectangle)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Square")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Square)i).Print();
                        }
                        else
                        if (i.GetType().Name == "Circle")
                        {
                            Console.WriteLine(i.GetType().Name + ":");
                            ((Circle)i).Print();
                        }
                    }

                    break;
                }

                case 3:
                {
                    Console.WriteLine("\nMatrix");
                    Matrix <Geometric_figures> matrix = new Matrix <Geometric_figures>(3, 3, 3, new FigureMatrixCheckEmpty());
                    matrix[0, 0, 0] = rect;
                    matrix[1, 1, 1] = scv;
                    matrix[2, 2, 2] = cir;
                    Console.WriteLine(matrix.ToString());

                    break;
                }

                case 4:
                {
                    SimpleStack <Geometric_figures> stack = new SimpleStack <Geometric_figures>();
                    stack.Push(rect);
                    stack.Push(scv);
                    stack.Push(cir);

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

                case 5:
                {
                    Console.WriteLine("Exiting.");
                    Console.ReadKey();
                    break;
                }

                default:
                {
                    Console.WriteLine("ERROR");
                }
                break;
                }
            }
            return(0);
        }
Example #20
0
        static void Main(string[] args)
        {
            Circle    circle    = new Circle(5);
            Square    square    = new Square(5);
            Rectangle rectangle = new Rectangle(5, 4);

            circle.Print();
            square.Print();
            rectangle.Print();

            List <Figura> li1 = new List <Figura>
            {
                circle, square, rectangle
            };

            Console.WriteLine();
            Console.WriteLine("Сортировка коллекции класса List<Figure>");
            li1.Sort();
            foreach (var x in li1)
            {
                Console.WriteLine(x);
            }

            ArrayList li2 = new ArrayList();

            li2.Add(circle);
            li2.Add(square);
            li2.Add(rectangle);
            li2.Sort();
            Console.WriteLine();
            Console.WriteLine("Сортировка коллекции класса ArrayList");
            foreach (var x in li2)
            {
                Console.WriteLine(x);
            }

            Console.WriteLine();
            Console.WriteLine("\n Разреженная матрица");
            Matrix <Figura> matrix = new Matrix <Figura>(3, 3, 3,
                                                         new FigureMatrixCheckEmpty());

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

            Console.WriteLine();
            Console.WriteLine("\n Стэээк");
            SimpleStack <Figura> stack = new SimpleStack <Figura>();

            //добавление данных в стек
            stack.Push(rectangle);
            stack.Push(square);
            stack.Push(circle);
            //чтение данных из стека
            while (stack.Count > 0)
            {
                Figura f = stack.Pop();
                Console.WriteLine(f);
            }



            Console.ReadLine();
        }
Example #21
0
        static void Main(string[] args)
        {
            Console.Title           = "Нагдимаев Ильягу ИУ5-35Б Лаб.3";
            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            //task #2-3
            Rectangle rect   = new Rectangle(5, 10);
            Square    square = new Square(5);
            Circle    circle = new Circle(5);

            //task #4
            Console.WriteLine("ArrayList");
            ArrayList Alist = new ArrayList();

            Alist.Add(rect);
            Alist.Add(square);
            Alist.Add(circle);
            foreach (var x in Alist)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("ArrayList sorted");
            Alist.Sort();
            foreach (var x in Alist)
            {
                Console.WriteLine(x);
            }

            //task #5
            Console.WriteLine("\nList");
            List <Figure> list = new List <Figure>();

            list.Add(rect);
            list.Add(square);
            list.Add(circle);
            foreach (var x in list)
            {
                Console.WriteLine(x);
            }
            Console.WriteLine("List sorted");
            list.Sort();
            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            //task #6
            Console.WriteLine("\nМатрица");
            Matrix <Figure> matrix = new Matrix <Figure>(3, 3, 2, new FigureMatrixCheckEmpty());

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

            try
            {
                Figure temp = matrix[123, 123, 12];
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
            }

            //task #7
            Console.WriteLine("\nСтэк");
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rect);
            stack.Push(square);
            stack.Push(circle);
            while (stack.Count > 0)
            {
                Figure f = stack.Pop();
                Console.WriteLine(f);
            }
            Console.ReadKey();
        }
Example #22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Кучумов Вячеслав Олегович, ИУ5-33Б");
            Rectangle rect   = new Rectangle(2, 3);
            Quadrat   quad   = new Quadrat(5);
            Circle    circle = new Circle(3);

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

            a1.Add(circle);
            a1.Add(rect);
            a1.Add(quad);
            foreach (var x in a1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nArrayList-sort");
            a1.Sort();

            foreach (var x in a1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nList<Figure>");
            List <Figure> f1 = new List <Figure>();

            f1.Add(circle);
            f1.Add(rect);
            f1.Add(quad);

            foreach (var x in f1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nList<Figure>-sort");
            f1.Sort();

            foreach (var x in f1)
            {
                Console.WriteLine(x.ToString());
            }
            Console.WriteLine("\nMatrix");
            SparseMatrix <Figure> matrix = new SparseMatrix <Figure>(4, 4, 4, null);

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

            Console.WriteLine("\nStack");
            SimpleStack <Figure> stack = new SimpleStack <Figure>();

            stack.Push(rect);
            stack.Push(quad);
            stack.Push(circle);
            foreach (var x in stack)
            {
                Console.WriteLine(x.ToString());
            }

            Console.WriteLine("\nStack-pop");
            stack.Pop();
            foreach (var x in stack)
            {
                Console.WriteLine(x.ToString());
            }
        }