Exemplo n.º 1
0
        static void TestRemovePalindrome()
        {
            var lst = new WordSet(new string[] { "ab", "abb", "bab", "aba", "abc", "abababa" });

            lst.RemovePalindrome();
            Console.WriteLine(lst.ToString());
        }
Exemplo n.º 2
0
        static void TestNewWordSetByWordLength()
        {
            var lst = new WordSet(new string[] { "a", "aa", "aaa", "bb", "bbbb", "cc" });

            lst = lst.NewWordSetByWordLength(2);
            Console.WriteLine(lst.ToString());
        }
Exemplo n.º 3
0
        static void TestVowelDivide()
        {
            var lst = new WordSet(new string[] { "а", "б", "в", "г", "д", "е" });
            var arr = lst.VowelDivide();

            Console.WriteLine("{0} | {1}", arr[0], arr[1]);
        }
Exemplo n.º 4
0
        static void TestInsert()
        {
            var lst = new WordSet(new string[] { "c", "a", "d" });

            lst.Insert("b");
            Console.WriteLine(lst.ToString());
        }
Exemplo n.º 5
0
        static void TestDelete()
        {
            var lst = new WordSet(new string[] { "c", "a", "d", "b" });

            lst.Delete("c");
            Console.WriteLine(lst.ToString());
        }
Exemplo n.º 6
0
        public WordSet[] VowelDivide()
        {
            var vovel     = ("аеёиоуыэюя" + "аеёиоуыэюя".ToUpper()).ToCharArray();
            var consonant = ("бвгджзйклмнпрстфхцчшщъь" + "бвгджзйклмнпрстфхцчшщъь".ToUpper()).ToCharArray();

            var vovelWordSet     = new WordSet();
            var consonantWordSet = new WordSet();

            var el = First;

            while (el != null)
            {
                if (IsLetterContainedInArray(el.Info[0], vovel))
                {
                    vovelWordSet.AddLast(el.Info);
                }
                else
                {
                    consonantWordSet.AddLast(el.Info);
                }
                el = el.Next;
            }

            return(new WordSet[] { consonantWordSet, vovelWordSet });
        }
Exemplo n.º 7
0
        static void TestTwoWordSets()
        {
            var lst1 = new WordSet(new string[] { "a", "r", "s" });
            var lst2 = new WordSet(new string[] { "z", "b", "o" });
            var lst  = new WordSet(lst1, lst2);

            Console.WriteLine(lst);
        }
Exemplo n.º 8
0
        //Вариант 2
        static void Main(string[] args)
        {
            var words = File.ReadAllLines("Words.txt");
            var lst1  = new WordSet(words);
            var lst2  = new WordSet(words);

            Console.WriteLine(new WordSet(lst1, lst2));
            Console.ReadKey();
        }
Exemplo n.º 9
0
        public WordSet NewWordSetByWordLength(int l)
        {
            var wordList = new List <string>();
            var el       = First;

            while (el != null)
            {
                if (el.Info.Length == l)
                {
                    wordList.Add(el.Info);
                }
                el = el.Next;
            }
            var fixedLengthWordSet = new WordSet(wordList.ToArray());

            return(fixedLengthWordSet);
        }
Exemplo n.º 10
0
        public WordSet(WordSet w1, WordSet w2)
        {
            if (!w1.IsOrdered() || !w2.IsOrdered())
            {
                throw new Exception("Списки не упорядочены");
            }

            var el1 = w1.First;
            var el2 = w2.First;
            var l3  = new WordSet();

            while (el1 != null && el2 != null)
            {
                if (el1.Info.CompareTo(el2.Info) < 0)
                {
                    l3.AddLast(el1.Info);
                    el1 = el1.Next;
                }
                else
                {
                    l3.AddLast(el2.Info);
                    el2 = el2.Next;
                }
            }
            if (el1 == null)
            {
                while (el2 != null)
                {
                    l3.AddLast(el2.Info);
                    el2 = el2.Next;
                }
            }
            else
            {
                while (el1 != null)
                {
                    l3.AddLast(el1.Info);
                    el1 = el1.Next;
                }
            }
            First = l3.First;
        }
Exemplo n.º 11
0
        public WordSet(WordSet w1, WordSet w2) // Не работает метод override .ToString(), т.к. First после этой оргии равен null
        {
            if (!w1.IsOrdered() || !w2.IsOrdered())
            {
                throw new Exception("Списки не упорядочены");
            }

            var el1 = w1.First;
            var el2 = w2.First;
            var l3  = new SingleLinkedList();

            while (el1 != null && el2 != null)
            {
                if (el1.Info.CompareTo(el2.Info) < 0)
                {
                    l3.AddLast(el1.Info); // n^2 time, would be better memorizing last element
                    el1 = el1.Next;
                }
                else
                {
                    l3.AddLast(el2.Info); // same here
                    el2 = el2.Next;
                }
            }
            if (el1 == null) // can be folded into Elem e = el1 == null ? el2 : el1; while(e != null) {...}
            {
                while (el2 != null)
                {
                    l3.AddLast(el2.Info);
                    el2 = el2.Next;
                }
            }
            else
            {
                while (el1 != null)
                {
                    l3.AddLast(el1.Info);
                    el1 = el1.Next;
                }
            }
        }
Exemplo n.º 12
0
        static void TestOut()
        {
            var lst = new WordSet(new string[] { "c", "b", "a", "d" });

            lst.Out("output.txt");
        }