예제 #1
0
파일: Program.cs 프로젝트: awDelya/Ex9
 public static void Create()
 {
     Color.Print("\nВведите количество элементов: ", ConsoleColor.Yellow);
     size      = Number.Check(1, int.MaxValue);
     HowCreate = Text.HowAdd();
     beg       = MakeListTwo();
 }
예제 #2
0
파일: Program.cs 프로젝트: awDelya/Ex9
 static PointTwo MakeListTwo()
 {
     beg = MakePointTwo(1);//создает первый элемент
     for (int i = 1; i < size; i++)
     {
         beg = AddToTwo(beg, (i + 1));//добавляет  остальные элементы в начало
     }
     return(beg);
 }
예제 #3
0
파일: Program.cs 프로젝트: awDelya/Ex9
        static void ShowListTwo()
        {
            Console.WriteLine();
            if (beg == null)
            {
                Color.Print("Список пуст!\n", ConsoleColor.Red);
                return;
            }
            PointTwo temp = beg;

            Color.Print("Исходный список:\n", ConsoleColor.Yellow);
            while (temp != null)
            {
                Color.Print(Convert.ToString(temp), ConsoleColor.Cyan);
                temp = temp.next;//переход к следующему элементу
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: awDelya/Ex9
        static PointTwo AddToTwo(PointTwo beg, int numb)//добавление остальных элементов в начало
        {
            PointTwo x        = MakePointTwo(numb);
            PointTwo pointTwo = new PointTwo(x.data);

            if (beg == null)
            {
                return(pointTwo);
            }
            PointTwo temp = beg;

            while (temp.pred != null)
            {
                temp = temp.pred;
            }
            pointTwo.next = beg;
            beg.pred      = pointTwo;
            beg           = pointTwo;
            return(beg);
        }
예제 #5
0
파일: Program.cs 프로젝트: awDelya/Ex9
        public static PointTwo Delete()
        {
            if (beg == null)//список пустой
            {
                Color.Print(" Список пуст!\n ", ConsoleColor.Red);
                return(null);
            }
            ShowListTwo();
            Color.Print(" Номер удаляемого элемента: ", ConsoleColor.Green);
            int number = Number.Check(1, int.MaxValue);

            if (number == 1) //удаление в начале списка
            {
                beg = beg.next;
                if (beg != null)
                {
                    beg.pred = null;
                }
                return(beg);
            }
            PointTwo p = beg;

            for (int i = 1; i < number && p != null; i++)
            {
                p = p.next;
            }
            if (p == null)//если элемент не найден
            {
                Color.Print("Ошибка! Размер списка меньше, чем номер.\n", ConsoleColor.Red);
                return(beg);
            }
            //исключаем элемент из списка
            p.pred.next = p.next;
            if (p.next != null)
            {
                p.next.pred = p.pred;
            }
            Color.Print("\n Удалено!", ConsoleColor.Cyan);
            return(beg);
        }
예제 #6
0
파일: Program.cs 프로젝트: awDelya/Ex9
        public static void Finde()
        {
            if (beg == null)//список пустой
            {
                Color.Print(" Список пуст!\n ", ConsoleColor.Red);
                return;
            }
            Color.Print(" Номер искомого элемента: ", ConsoleColor.Green);
            int      number = Number.Check(1, int.MaxValue) - 1;
            PointTwo temp   = beg;

            for (int i = 0; i < number && temp != null; i++)
            {
                temp = temp.next;                                             //перебор элементов до нужного номера
            }
            if (temp == null)
            {
                Color.Print("Элемент не найден.\n", ConsoleColor.Red);
                return;
            }
            Color.Print("\n Элемент: " + temp, ConsoleColor.Green);
        }
예제 #7
0
파일: Program.cs 프로젝트: awDelya/Ex9
        static void Main()
        {
            Color.Print("\tВыберите пункт: \n", ConsoleColor.Yellow);
            Color.Print(" 1) Создать список " +
                        "\n 2) Печать списка " +
                        "\n 3) Удалить элемент по номеру " +
                        "\n 4) Найти элемент по номеру " +
                        "\n 5) Выход", ConsoleColor.Cyan);
            Color.Print("\n\n Цифра: ", ConsoleColor.Black, ConsoleColor.White);
            zadacha = Number.Check(1, 5);
            switch (zadacha)
            {
            case 1: Create(); Text.GoBackMenu(); Main(); break;

            case 2: ShowListTwo(); Text.GoBackMenu(); Main(); break;

            case 3: beg = Delete(); Text.GoBackMenu(); Main(); break;

            case 4: Finde(); Text.GoBackMenu(); Main(); break;

            case 5: break;
            }
        }
예제 #8
0
 //конструктор с параметром
 public PointTwo(string d)
 {
     data = d;
     next = null;
     pred = null;
 }
예제 #9
0
 //конструктор без параметров
 public PointTwo()
 {
     data = "";
     next = null;
     pred = null;
 }