Пример #1
0
        static void Main(string[] args)
        {
            using (reader = File.OpenText("input.txt"))
                using (writer = new StreamWriter(File.Create("output.txt")))
                {
                    int n = reader.ReadInt();
                    CustomStack <char> stack = new CustomStack <char>(10001);
                    while (n > 0)
                    {
                        stack.Clear();
                        string str   = reader.ReadToken();
                        bool   right = true;
                        for (int i = 0; i < str.Length && right; i++)
                        {
                            switch (str[i])
                            {
                            case '(':
                            case '[':
                                stack.Push(str[i]);
                                break;

                            case ')':
                                if (stack.IsEmpty())
                                {
                                    right = false;
                                }
                                else
                                {
                                    char c = stack.Pop();
                                    right = (c == '(');
                                }
                                break;

                            case ']':
                                if (stack.IsEmpty())
                                {
                                    right = false;
                                }
                                else
                                {
                                    char c = stack.Pop();
                                    right = (c == '[');
                                }
                                break;
                            }
                        }

                        right = right && stack.IsEmpty();

                        writer.WriteLine(right ? "YES" : "NO");
                        n--;
                    }
                }
        }
Пример #2
0
        public void IsEmpty_NormalConditions_Test()
        {
            CustomStack <int> testStack = new CustomStack <int>();
            var result = testStack.IsEmpty();

            Assert.That(result, Is.EqualTo(true));
        }
Пример #3
0
        public CustomStack <int> Sort(CustomStack <int> sourceStack)
        {
            var sortedStack = new CustomStack <int>();

            while (!sourceStack.IsEmpty())
            {
                var currentValue = sourceStack.Pop();

                while (!sortedStack.IsEmpty() && sortedStack.Peek() > currentValue)
                {
                    sourceStack.Push(sortedStack.Pop());
                }

                sortedStack.Push(currentValue);
            }

            return(sortedStack);
        }
Пример #4
0
        public void NotEmptyTest()
        {
            var stack = CustomStack <string> .Cons("Hello", CustomStack <string> .Empty);

            Assert.IsFalse(CustomStack <string> .IsEmpty(stack));
        }
Пример #5
0
        public void EmptyTest()
        {
            var stack = CustomStack <string> .Empty;

            Assert.IsTrue(CustomStack <string> .IsEmpty(stack));
        }
Пример #6
0
        private static void NewMethod()
        {
            CustomList <Person> people = new CustomList <Person>();

            people.Add(Pupil.GeneratePupil());
            people.Add(Pupil.GeneratePupil());
            people.Add(Pupil.GeneratePupil());
            people.Add(Student.GeneratePupil());
            people.Add(Student.GeneratePupil());
            people.Add(Student.GeneratePupil());

            Console.WriteLine(people.Count);

            foreach (var item in people)
            {
                Console.WriteLine(item.ToString());
            }

            foreach (var item in people)
            {
                Console.WriteLine(item.ToString());
            }

            CustomTree tree = new CustomTree();

            tree.Add(5);
            tree.Add(7);
            tree.Add(3);
            tree.Add(4);
            tree.Add(1);
            tree.Print();
            Console.WriteLine("---------------------------------");
            tree.PrintBfs();
            Console.WriteLine("---------------------------------");
            Console.WriteLine("---------------------------------");
            tree.PrintDfs();
            Console.WriteLine("---------------------------------");

            CustomIdealTree idealTree = new CustomIdealTree();

            idealTree.Add(10);
            idealTree.Add(5);
            idealTree.Add(6);
            idealTree.Add(3);
            idealTree.Add(8);
            idealTree.Print();

            CustomTree transformed = idealTree.TransformToCustomTree();

            transformed.Print();

            CustomStack <int> customStack = new CustomStack <int>(4, false);

            customStack.Push(5);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(6);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(7);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(8);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.ReallocateMemmory();
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");
            customStack.Push(9);
            Console.WriteLine($"Capacity = {customStack.Capacity}");

            while (!customStack.IsEmpty())
            {
                Console.WriteLine(customStack.Pop());
            }

            Custom.Collections.JavaList.CustomList <int> list = new Custom.Collections.JavaList.CustomList <int>();
            list.InsertFirst(10);
            list.InsertFirst(13);
            list.InsertFirst(15);
            list.InsertFirst(3);
            list.InsertFirst(17);
            list.InsertFirst(6);
            Console.WriteLine(list.ToString());
        }