コード例 #1
0
        private void WorkWithStack(int maxSize)
        {
            ShowName("Stack");
            StackStruct <long> stack = new StackStruct <long>(maxSize);

            Fill(stack, maxSize);
            try
            {
                stack.Insert(6);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Remove(stack);

            try
            {
                stack.Remove();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            ShowEndMessage();
        }
コード例 #2
0
        public long MathWithStack(int number)
        {
            StackStruct <long> stack = new StackStruct <long>(500);
            long answer = 0;

            while (number > 0)
            {
                stack.Insert(number--);
            }
            while (!stack.IsEmpty())
            {
                answer += stack.Remove();
            }

            return(answer);
        }