static void Main(string[] args)
        {
            NodeStack <string> stack = new NodeStack <string>();

            stack.Push("Tom");
            stack.Push("Alice");
            stack.Push("Bob");
            stack.Push("Kate");

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();
            string header = stack.Peek();

            Console.WriteLine($"Верхушка стека: {header}");
            Console.WriteLine();

            header = stack.Pop();
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            NodeStack <string> stack = new NodeStack <string>();

            #region Push

            Console.WriteLine("Push");

            stack.Push("Bob");
            stack.Push("Alice");
            stack.Push("Tom");

            stack.Display();

            #endregion

            #region Pop

            Console.WriteLine("Pop");
            Console.WriteLine(stack.Pop());
            Console.WriteLine();

            #endregion

            #region Peek

            Console.WriteLine("Peek");
            Console.WriteLine(stack.Peek());
            Console.WriteLine();

            #endregion

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string           str     = Console.ReadLine();
            NodeStack <char> stack   = new NodeStack <char>();
            NodeStack <int>  bracket = new NodeStack <int>();

            char[] open  = new char[] { '{', '[', '(' };
            char[] close = new char[] { '}', ']', ')' };
            for (int i = 0; i < str.Length; i++)
            {
                if (open.Contains(str[i]) || close.Contains(str[i]))
                {
                    if (stack.IsEmpty && close.Contains(str[i]))
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                    else if (stack.IsEmpty == false && Array.IndexOf(open, stack.Peek()) == Array.IndexOf(close, str[i]))
                    {
                        stack.Pop();
                        bracket.Pop();
                    }
                    else
                    {
                        bracket.Push(i + 1);
                        stack.Push(str[i]);
                    }
                }
            }
            if (stack.IsEmpty)
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine(bracket.Peek());
            }
            Console.ReadKey();
        }
Beispiel #4
0
 public Form1()
 {
     i = new NodeStack();
     InitializeComponent();
 }