예제 #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);
        }