static void Main(string[] args)
        {
            List LST = new List();

            bool[] no_yes = new bool[] { false, true };
            for (int i = 0; i < no_yes.Length; i++)
            {
                bool eneble_shuffle = no_yes[i];

                for (int j = 0; j < LST.ns.Length; j++)
                {
                    var arr = LST.FillIncreasing(LST.ns[j]);
                    if (eneble_shuffle)
                    {
                        LST.Shuffle(ref arr);
                    }
                    DateTime insertion_start = DateTime.Now;
                    for (int k = 0; k < arr.Length; k++)
                    {
                        Node iter = LST.Insert(arr[k]);
                        Debug.Assert(iter != null);
                        Debug.Assert(iter.value == arr[k]);
                    }
                    DateTime insertion_stop = DateTime.Now;
                    var      insertion_time = insertion_stop - insertion_start;

                    LST.Shuffle(ref arr);

                    DateTime search_start = DateTime.Now;
                    for (int k = 0; k < arr.Length; k++)
                    {
                        Node iter = LST.Search(arr[k]);
                        Debug.Assert(iter != null);
                        Debug.Assert(iter.value == arr[k]);
                    }
                    DateTime search_stop = DateTime.Now;
                    var      search_time = search_stop - search_start;

                    LST.Shuffle(ref arr);

                    for (int k = 0, l = arr.Length; k < arr.Length; k++, l--)
                    {
                        Debug.Assert(LST.Size() == l);
                        LST.Delete(arr[k]);
                    }
                    Debug.Assert(LST.Size() == 0);
                    Debug.Assert(LST.head == null);

                    Console.WriteLine("{0}, {1}, {2}, {3}", arr.Length, no_yes[i], insertion_time, search_time);
                }
            }
        }
Beispiel #2
0
        private static void EventLoop(List list)
        {
            Menu();

            int choice = 1;

            while (choice != 0)
            {
                WriteLine();
                WriteLine("Enter your choice: ");
                string input = ReadLine();
                while (!int.TryParse(input, out choice))
                {
                    WriteLine("It`s not a number, try again: ");
                    input = ReadLine();
                }

                switch (choice)
                {
                case 1:
                {
                    WriteLine("Enter the element: ");
                    string str = ReadLine();
                    WriteLine("Enter the position: ");
                    string position = ReadLine();

                    list.Add(str, position);
                    break;
                }

                case 2:
                {
                    WriteLine("Enter the element: ");
                    string str = ReadLine();

                    list.DeleteElement(str);
                    break;
                }

                case 3:
                {
                    WriteLine($"The length of the list: {list.Size()}");
                    break;
                }

                case 4:
                {
                    WriteLine("Enter the number: ");
                    string str = ReadLine();

                    string meaning = list.ReturnString(str);
                    if (meaning == "")
                    {
                        WriteLine("There`s no such element");
                    }
                    else
                    {
                        WriteLine($"The element number {str}: {meaning}");
                    }
                    break;
                }

                case 5:
                {
                    list.Print();
                    break;
                }

                case 6:
                {
                    if (list.IsEmpty())
                    {
                        WriteLine("The list is empty");
                    }
                    else
                    {
                        WriteLine("The list isn`t empty");
                    }
                    break;
                }

                case 7:
                {
                    list.Clean();
                    WriteLine("The list is deleted");
                    break;
                }

                case 0:
                {
                    break;
                }

                default:
                {
                    WriteLine("The wrong number, try again");
                    break;
                }
                }
            }
        }