Beispiel #1
0
        internal static void Execute()
        {
            EasyTimer timer = new EasyTimer();
            String    times = String.Empty;
            String    time  = String.Empty;

            int[] ints = new int[100000];
            for (int i = 0; i < ints.Length; i++)
            {
                ints[i] = i;
            }
            ints.Shuffle();
            AddText("Merge", ref times);
            #region Merge
            timer.Start();
            ints = Sorter.MergeSort(ints);
            SaveTime("Random: ", ref times, ref timer);
            timer.Start();
            ints = Sorter.MergeSort(ints);
            SaveTime("Ascending: ", ref times, ref timer);
            ints.Reverse();
            timer.Start();
            ints = Sorter.MergeSort(ints);
            SaveTime("Descending: ", ref times, ref timer);
            #endregion
            AddText("Heap", ref times);
            ints.Shuffle();
            #region Heap
            timer.Start();
            ints = Sorter.HeapSort(ints);
            SaveTime("Random: ", ref times, ref timer);
            timer.Start();
            ints = Sorter.HeapSort(ints);
            SaveTime("Ascending: ", ref times, ref timer);
            ints.Reverse();
            timer.Start();
            ints = Sorter.HeapSort(ints);
            SaveTime("Descending: ", ref times, ref timer);
            #endregion
            AddText("Quick", ref times);
            ints.Shuffle();
            #region Quick
            timer.Start();
            Sorter.QuickSort(ints, 0, ints.Length - 1);
            SaveTime("Random: ", ref times, ref timer);
            timer.Start();
            Sorter.QuickSort(ints, 0, ints.Length - 1);
            SaveTime("Ascending: ", ref times, ref timer);
            ints.Reverse();
            timer.Start();
            Sorter.QuickSort(ints, 0, ints.Length - 1);
            SaveTime("Descending: ", ref times, ref timer);
            #endregion
            FileExpert.SaveToRelativePath("sorted.dat", times.Trim());
        }
Beispiel #2
0
        private void buttonDraw_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog {
                Filter = "Text Files | *.txt", DefaultExt = "txt"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string input = FileExpert.ReadFromAbsolutePath(ofd.FileName);

            strings = input.Trim().Split('\n');
            var g = pictureBox1.CreateGraphics();

            DrawText(g);
        }
Beispiel #3
0
        private void SaveToFile(string num)
        {
            strings = Lines;
            var sfd = new SaveFileDialog {
                Filter = "Text Files | *.txt", DefaultExt = "txt"
            };

            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var output = strings.Aggregate("", (current, line) => current + (line + "\n"));

            output = output.Trim();
            if (num.Length > 0 && int.Parse(num) < strings.Length)
            {
                string[] lines = output.Split('\n');
                output = string.Join(Environment.NewLine, lines.Take(int.Parse(num)));
            }
            FileExpert.SaveToAbsolutePath(sfd.FileName, output);
            MessageBox.Show($"Сохранено в файл {sfd.FileName}");
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            int choice = 0;

            do
            {
                Console.WriteLine("Выберите пункт");
                Console.WriteLine("1 - Просмотр таблицы");
                Console.WriteLine("2 - Добавить запись");
                Console.WriteLine("3 - Удалить запись");
                Console.WriteLine("4 - Обновить запись");
                Console.WriteLine("5 - Поиск записей");
                Console.WriteLine("6 - Просмотреть лог");
                Console.WriteLine("7 - Выход");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case WATCH_TABLE:
                    Console.WriteLine("{0,10} {1,10} {2,10} {3,10}", "Вид транспорта", "№ маршрута", "Протяженность маршрута (км) ", "Время в дороге (мин)");
                    for (int list_item = 0; list_item < list.Count; list_item++)
                    {
                        HRD t = list[list_item];
                        Console.WriteLine("----------------------------------------------------------------------------\n");
                        t.ShowTable(t.Transport, t.number, t.Length, t.RoadTime);
                    }

                    string textFromFile = FileExpert.ReadFromRelativePath("lab.dat");
                    Console.WriteLine(textFromFile);
                    Logging.Add(DateTime.Now, Operations.LOOK, "Просмотрена таблица");
                    break;

                case ADD_RAW:
                    HRD t1;
                    Console.WriteLine("Введите Вид транспорта");
                    t1.Transport = Console.ReadLine();
                    Console.WriteLine("Введите Номер маршрута");
                    t1.number = Console.ReadLine();

Found1:
                    Console.WriteLine("Введите Протяженность маршрута (км) ");
                    try
                    {
                        int enter_length = Convert.ToInt32(Console.ReadLine());     //вводим данные, и конвертируем в целое число
                        t1.Length = enter_length;
                        if ((enter_length <= 0) || (enter_length >= 250))
                        {
                            Console.WriteLine("Error. (Введите повторно)");
                            goto Found1;
                        }
                    }
                    catch (FormatException)
                    {
                        t1.Length = 000;
                        Console.WriteLine("Error. (Введите повторно)");
                        goto Found1;
                    }
                    Pos pro;
Found3:
                    Console.WriteLine("Время в дороге (мин)");
                    try
                    {
                        string enter_length3 = Console.ReadLine();
                        t1.RoadTime = enter_length3;
                        pro         = (Pos)Enum.Parse(typeof(Pos), enter_length3);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error. (Введите повторно)");
                        pro = Pos.None;
                        goto Found3;
                    }

                    list.Add(t1);
                    Console.WriteLine("Строка была добавлена!");
                    Console.WriteLine();
                    Logging.Add(DateTime.Now, Operations.ADD, "Строка добавлена в таблицу!");
                    break;

                case REMOVE_RAW:


                    Console.WriteLine("Введите номер строки, которую хотите удалить");
                    int number = int.Parse(Console.ReadLine());
                    try
                    {
                        list.RemoveAt(number - 1);
                    }
                    catch (Exception e) { Console.WriteLine("Строки с таким номером нет!"); }
                    Console.WriteLine();
                    Logging.Add(DateTime.Now, Operations.ADD, "Строка удалена!");
                    break;

                case UPDATE_RAW:
                    Console.WriteLine("Введите номер строки, которую хотите изменить");
                    int UpdateIndex = int.Parse(Console.ReadLine());
                    try
                    {
                        HRD t2 = list[UpdateIndex - 1];

                        //Выводим старые значения

                        t2.ShowTable(t2.Transport, t2.number, t2.Length, t2.RoadTime);


                        //Вводим новые значения

                        Console.WriteLine("Введите новый вид транспорта");
                        t2.Transport = Console.ReadLine();
                        Console.WriteLine("Введите новый № маршрута ");
                        t2.number = Console.ReadLine();
                        Console.WriteLine("Введите новую протяженность маршрута (км) ");
Found2:
                        t2.Length = int.Parse(Console.ReadLine());
                        try
                        {
                            int enter_length2 = Convert.ToInt32(Console.ReadLine());     //вводим данные, и конвертируем в целое число
                            t2.Length = enter_length2;
                            if ((enter_length2 < 1895) || (enter_length2 > 2030))
                            {
                                Console.WriteLine("Error. (Введите повторно)");
                                goto Found2;
                            }
                        }
                        catch (FormatException)
                        {
                            t2.Length = 000;
                            Console.WriteLine("Error. (Введите повторно)");
                            goto Found2;
                        }
                        Console.WriteLine("Введите новый Тип");
                        Pos pro2;
Found4:
                        try
                        {
                            string enter_length4 = Console.ReadLine();
                            t2.RoadTime = enter_length4;
                            pro2        = (Pos)Enum.Parse(typeof(Pos), enter_length4);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error. (Введите повторно)");
                            pro2 = Pos.None;
                            goto Found4;
                        }
                        list[UpdateIndex - 1] = t2;
                    }
                    catch (Exception e) { Console.WriteLine("Нет строки с таким номером!"); }
                    Logging.Add(DateTime.Now, Operations.ADD, "Строка обновлена!");
                    break;

                case FIND_RAW:
                    Console.WriteLine("Введите фамилию");
                    string text = Console.ReadLine();
                    HRD    FindRaw;
                    for (int item_list = 0; item_list < list.Count; item_list++)
                    {
                        FindRaw = list[item_list];
                        if (FindRaw.Transport.ToLower().Equals(text.ToLower()))
                        {
                            Console.Write("{0,10}", FindRaw.Transport);
                            Console.Write("{0,10}", FindRaw.number);
                            Console.Write("{0,10}", FindRaw.Length);
                            Console.Write("{0,10}", FindRaw.RoadTime);
                            Console.WriteLine();
                        }
                    }
                    Logging.Add(DateTime.Now, Operations.ADD, "Строка найдена!");
                    break;

                case SHOW_LOG:
                    Logging.Add(DateTime.Now, Operations.ADD, "Логи просмотрены!");
                    Logging.ShowInfo();
                    break;

                case EXIT:

                    String file = string.Empty;
                    foreach (var t in list)
                    {
                        file += "----------------------------------------------------------------------------";
                        file += t.Transport + "\t" + t.number + "\t" + t.Length + "\t" + t.RoadTime;
                    }
                    //for (int list_item = 0; list_item < list.Count; list_item++)
                    //{
                    //    HRD t = list[list_item];
                    //    write.WriteLine("----------------------------------------------------------------------------");
                    //    write.WriteLine("{0,10} {1,10} {2,10} {3,10}" , t.Transport, t.number, t.Length, t.RoadTime);
                    // }

                    FileExpert.SaveToRelativePath("lab.dat", file);
                    break;
                }
            } while (choice != 7);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Random rnd    = new Random();
            long   count1 = 0;
            long   count2 = 0;
            int    length = 100;

            int[] arrarevers = new int[length];
            int[] array      = new int[length];
            for (int i = 0; i < length; i++)
            {
                array[i]      = rnd.Next(-999, 999);
                arrarevers[i] = array[i];
            }
            TimeSpan SWT;
            TimeSpan IWT;
            TimeSpan BWT;
            TimeSpan ShakerWT;
            TimeSpan ShellWT;

            ShellSort(array, length, out ShellWT, out count1, out count2);
            Array.Reverse(array);
            ShellSort(arrarevers, length, out ShellWT, out count1, out count2);

            String file = string.Empty;

            foreach (int number in arrarevers)
            {
                file += number + ",";
            }
            FileExpert.SaveToRelativePath(path, file);

            String file1 = string.Empty;

            foreach (int number in array)
            {
                file1 += (number + ",");
            }
            FileExpert.SaveToRelativePath(path1, file1);

            int select = 0;

            while (select != 4)
            {
                Console.WriteLine("1 - Random array");
                Console.WriteLine("2 - array> and <");
                Console.WriteLine("3 - array< and >");
                Console.WriteLine("4 - exit");
                select = int.Parse(Console.ReadLine());
                switch (select)
                {
                case 1:
                    Console.WriteLine("Rnd array");
                    SelectionSort(array, length, out SWT, out count1, out count2);
                    InsertionSort(array, length, out IWT, out count1, out count2);
                    BubbleSort(array, length, out BWT, out count1, out count2);
                    ShakerSort(array, length, out ShakerWT, out count1, out count2);
                    ShellSort(array, length, out ShellWT, out count1, out count2);
                    break;

                case 2:
                    Console.WriteLine("Array> and <\n");
                    SelectionSort(array, length, out SWT, out count1, out count2);
                    InsertionSort(array, length, out IWT, out count1, out count2);
                    BubbleSort(array, length, out BWT, out count1, out count2);
                    ShakerSort(array, length, out ShakerWT, out count1, out count2);
                    ShellSort(array, length, out ShellWT, out count1, out count2);
                    break;

                case 3:
                    Console.WriteLine("Array < and >\n");
                    SelectionSort(arrarevers, length, out SWT, out count1, out count2);
                    InsertionSort(arrarevers, length, out IWT, out count1, out count2);
                    BubbleSort(arrarevers, length, out BWT, out count1, out count2);
                    ShakerSort(arrarevers, length, out ShakerWT, out count1, out count2);
                    ShellSort(arrarevers, length, out ShellWT, out count1, out count2);
                    break;
                }
            }
        }