Esempio n. 1
0
        private static void LoadList()
        {
            var options = OurList.Keys.ToList();

            for (var index = 0; index < options.Count; index++)
            {
                var listName = options[index];
                Console.WriteLine($"{index} - {listName}");
            }

            while (true)
            {
                Console.WriteLine("Enter the number or name of the list to load, or a new name to add");
                CurrentLoadedList = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(CurrentLoadedList))
                {
                    break;
                }
            }

            if (int.TryParse(CurrentLoadedList, out int selected) && selected < options.Count && selected >= 0)
            {
                CurrentLoadedList = options[selected];
            }
            else if (!options.Select(x => x.ToLower()).Contains(CurrentLoadedList.ToLower()))
            {
                OurList.Add(CurrentLoadedList, new List <TagalogListItem>());
            }
            else
            {
                CurrentLoadedList =
                    options.Find(x => x.Equals(CurrentLoadedList, StringComparison.CurrentCultureIgnoreCase));
            }
            Console.Clear();
        }
Esempio n. 2
0
        public static int InsertSort(OurList <int> list)
        {
            int count = 0;

            for (int i = 0; i < list.Lenght(); i++)
            {
                int remember = list.Get(i); count += i;
                int place    = 0;
                while (remember < list.Get(place))
                {
                    count += place;
                    place  = place + 1;
                    count++;
                }
                if (place < i)
                {
                    for (int j = i; j > place; j--)
                    {
                        list.Set(list.Get(j - 1), j);
                        count += j - 1 + j;
                        count++;
                    }
                    list.Set(remember, place);
                    count += place;
                }
                count++;
            }
            return(count);
        }
Esempio n. 3
0
        public void Add_Test()
        {
            var numberToAdd = 1;
            var ourList     = new OurList <int>();

            ourList.Add(numberToAdd);

            Assert.Contains(numberToAdd, ourList);
        }
Esempio n. 4
0
        public void Contains_Test()
        {
            var ourList = new OurList <int> {
                5
            };
            var result = ourList.Contains(5);

            Assert.True(result);
        }
Esempio n. 5
0
        static public int BinarySearchOurList(OurList <long> Ourlist, int a)
        {
            int length  = Ourlist.Lenght();
            int element = 0;
            int half    = length / 2;
            int half2   = length / 2;

            for (int k = 0; k < length; k++)
            {
                if (a > Ourlist.Get(half))
                {
                    if (half % 2 == 0)
                    {
                        half2 = half2 / 2;
                    }
                    else
                    {
                        half2 = half2 / 2 + 1;
                    }
                    half = half + half2;
                    element++;
                    element += half;
                }
                else
                if (a < Ourlist.Get(half))
                {
                    if (half % 2 == 0)
                    {
                        half2 = half2 / 2;
                    }
                    else
                    {
                        half2 = half2 / 2 + 1;
                    }
                    half = half - half2;
                    element++;
                    element += half;
                }
                else
                if (a == Ourlist.Get(half))
                {
                    element++;
                    element += half;
                    break;
                }
            }
            return(element);
        }
Esempio n. 6
0
        protected static void TestOurList()
        {
            Assert.IsTrue(true, "Start of test");
            var xListClasses = new OurList <KVPClass>();
            var xListStructs = new OurList <KVPStruct>();

            xListClasses.Add(new KVPClass {
                Key = 1, Value = 2
            });
            xListClasses.Add(new KVPClass {
                Key = 2, Value = 5
            });

            OurList <KVPClass> .ExpectedIndex = 0;
            var xListItem = xListClasses[0];

            Assert.AreEqual(1, xListItem.Key, "xListClasses[0].Key == 1");
            Assert.AreEqual(2, xListItem.Value, "xListClasses[0].Value == 2");
            OurList <KVPClass> .ExpectedIndex = 1;
            xListItem = xListClasses[1];
            Assert.AreEqual(2, xListItem.Key, "xListClasses[1].Key == 2");
            Assert.AreEqual(5, xListItem.Value, "xListClasses[1].Value == 5");

            xListStructs.Add(new KVPStruct {
                Key = 1, Value = 2
            });
            xListStructs.Add(new KVPStruct {
                Key = 2, Value = 5
            });

            OurList <KVPStruct> .ExpectedIndex = 0;
            var xStructItem = xListStructs[0];

            Assert.AreEqual(1, xStructItem.Key, "xListStructs[0].Key == 1");
            Assert.AreEqual(2, xStructItem.Value, "xListStructs[0].Value == 2");
            OurList <KVPStruct> .ExpectedIndex = 1;
            xStructItem = xListStructs[1];
            Assert.AreEqual(2, xStructItem.Key, "xListStructs[1].Key == 2");
            Assert.AreEqual(5, xStructItem.Value, "xListStructs[1].Value == 5");
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            ///ПОИСК ЭЛЕМЕНТА В МАССИВЕ
            var Ran = new Random();
            int s   = 90000;

            long[] mass3 = new long[s];
            int    a     = Ran.Next(1, s);

            for (int i = 0; i < s; i++)
            {
                mass3[i] = i;
            }
            OurList <long> list2 = new OurList <long>();

            for (int i = 1; i < s; i++)
            {
                list2.Add(i);
            }
            Console.WriteLine("Нашли число " + a + " за " + BinarySearchOurList(list2, a) + " шага(ов).");
            Console.WriteLine("Нашли число " + a + " за " + BinarySearch(mass3, a) + " шага(ов).");



            int count = 0;

            Console.WriteLine("Введите длину массива/списка для сортировки");
            int lenght = int.Parse(Console.ReadLine());

            int[] mass  = new int[lenght];
            int[] mass2 = new int[lenght];


            for (int i = 0; i < lenght; i++)
            {
                mass[i] = Ran.Next(1, lenght);
            }
            Array.Copy(mass, mass2, mass.Length);
            OurList <int> list = new OurList <int>();

            for (int i = 0; i < mass.Length; i++)
            {
                list.Add(mass[i]);
            }



            ///СОРТИРОВКА МАССИВА ВСТАВКОЙ
            Console.WriteLine("\nИсходный массив:");
            for (int i = 0; i < mass.Length; i++)
            {
                Console.Write(mass[i] + " ");
            }

            count = InsertSort(mass);

            Console.WriteLine("\nОтсортированный массив: ");
            for (int i = 0; i < mass.Length; i++)
            {
                Console.Write(mass[i] + " ");
            }
            Console.WriteLine("\nКоличество итерраций при сортировке массива вставкой длинной " + mass.Length + ": " + count);


            ///СОРТИРОВКА СПИСКА ВСТАВКОЙ

            Console.WriteLine("\nИсходный список:");
            for (int i = 0; i < list.Lenght(); i++)
            {
                Console.Write(list.Get(i) + " ");
            }

            count = InsertSort(list);

            Console.WriteLine("\nОтсортированный список: ");
            for (int i = 0; i < list.Lenght(); i++)
            {
                Console.Write(list.Get(i) + " ");
            }
            Console.WriteLine("\nКоличество итерраций при сортировке списка вставкой длинной " + list.Lenght() + ": " + count);


            ///СОРТИРОВКА МАССИВА КОРЗИНКАМИ

            Console.WriteLine("\nИсходный массив:");
            for (int i = 0; i < mass2.Length; i++)
            {
                Console.Write(mass2[i] + " ");
            }
            Console.WriteLine("\nВведите количество корзинок");
            int n = int.Parse(Console.ReadLine());

            count = BucketSort(mass2, 10);

            Console.WriteLine("\nОтсортированный массив: ");
            for (int i = 0; i < mass2.Length; i++)
            {
                Console.Write(mass2[i] + " ");
            }

            Console.WriteLine("\nКоличество итерраций при сортировке массива корзинками длинной " + mass2.Length + ": " + count);
            Console.ReadKey();
        }