当前位置: 首页>>代码示例>>C#>>正文


C# Stack.Min方法代码示例

本文整理汇总了C#中Stack.Min方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Min方法的具体用法?C# Stack.Min怎么用?C# Stack.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack.Min方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            int[] inputNums = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse).ToArray();
            int[] array = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse).ToArray();
            var stack = new Stack<int>();
            for (int i = 0; i < array.Length; i++)
            {
                stack.Push(array[i]);
            }

            for (int i = 0; i < inputNums[1]; i++)
            {
                stack.Pop();
            }

            if (stack.Contains(inputNums[2]))
            {
                Console.WriteLine("true");
            }
            else if (!stack.Contains(inputNums[2]) && stack.Count > 0)
            {
                Console.WriteLine(stack.Min());
            }
            else
            {
                Console.WriteLine(0);
            }
        }
开发者ID:Razkolnikow,项目名称:AdvancedCSharpHomeWorks,代码行数:30,代码来源:Program.cs

示例2: Main

    static void Main(string[] args)
    {
        // Take main input
        int[] input = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        Stack<int> stack = new Stack<int>();
        int push = input.First();
        int pop = input[1];
        int find = input.Last();

        // Fill the stack
        int[] stackInput = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        for (int i = 0; i < push; i++)
        {
            stack.Push(stackInput[i]);
        }

        // Pop the stack
        for (int i = 0; i < pop; i++)
        {
            if (stack.Count > 0)
            {
                stack.Pop();
            }
        }

        // Output
        if (stack.Contains(find))
        {
            Console.WriteLine("true");
        }
        else
        {
            Console.WriteLine(stack.Count > 0 ? stack.Min() : 0);
        }
    }
开发者ID:eMagicMan,项目名称:Study-CSharp,代码行数:35,代码来源:BasicStackOperations.cs

示例3: PrintResult

        private static void PrintResult(Stack<int> stackNumber, List<int> commands)
        {
            if (stackNumber.Count <= 0)
            {
                Console.WriteLine(0);
                return;
            }

            bool isContains = stackNumber.Contains(commands[2]);
            if (isContains)
            {
                Console.WriteLine("true");
            }
            else
            {
                int minValue = stackNumber.Min();
                Console.WriteLine(minValue);
            }
        }
开发者ID:IskraNikolova,项目名称:Advanced-CSharp,代码行数:19,代码来源:BasicStackOperation.cs

示例4: Main

        public static void Main()
        {
            //commands:
            //first number = amount of elements to push into the stack
            // second number = amount of elements to pop from the stack
            //third number = element to check if is contained in the stack
            int[] commandNumbers =
                Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(int.Parse)
                    .ToArray();

            int[] inputNumbers =
                Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(int.Parse)
                    .ToArray();

            Stack<int> numbers = new Stack<int>();

            for (int i = 0; i < commandNumbers[0]; i++)
            {
                numbers.Push(inputNumbers[i]);
            }

            for (int i = 0; i < commandNumbers[1]; i++)
            {
                numbers.Pop();
            }

            if (numbers.Count <= 0)
            {
                Console.WriteLine(0);
            }
            else if (numbers.Contains(commandNumbers[2]))
            {
                Console.WriteLine(true);
            }
            else
            {
                Console.WriteLine(numbers.Min());
            }
        }
开发者ID:Mario-Chaushki,项目名称:master,代码行数:43,代码来源:BasicStackOperations.cs

示例5: Main

        static void Main(string[] args)
        {
            int[] arguments = Console.ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();
            int[] itemsToPush = Console.ReadLine()
             .Split()
             .Select(int.Parse)
             .ToArray();
            Stack<int> stk=new Stack<int>();

            for (int i = 0; i < arguments[0]; i++)
            {
                stk.Push(itemsToPush[i]);
            }
            for (int i = 0; i < arguments[1]; i++)
            {
                stk.Pop();
            }

            if (stk.Contains(arguments[2]))
            {
                Console.WriteLine("true");
            }
            else
            {
                if (stk.Count > 0)
                {
                    Console.WriteLine(stk.Min());
                }
                else
                {
                    Console.WriteLine(0);
                }
            }
        }
开发者ID:AlexanderKrustev,项目名称:SoftUni,代码行数:37,代码来源:BasicStackOperations.cs

示例6: StackExtensions_Min_ThrowsExceptionIfStackIsEmpty

        public void StackExtensions_Min_ThrowsExceptionIfStackIsEmpty()
        {
            var stack = new Stack<Int32>();

            Assert.That(() => stack.Min(),
                Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:7,代码来源:StackExtensionsTest.cs

示例7: StackExtensions_Min_ReturnsMinValue

        public void StackExtensions_Min_ReturnsMinValue()
        {
            var stack = new Stack<Int32>();
            stack.Push(4);
            stack.Push(5);
            stack.Push(6);
            stack.Push(99);
            stack.Push(10);
            stack.Push(1);
            stack.Push(12);
            stack.Push(45);

            var result = stack.Min();

            TheResultingValue(result).ShouldBe(1);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:16,代码来源:StackExtensionsTest.cs

示例8: StackExtensions_Min_ThrowsExceptionIfStackIsEmpty

        public void StackExtensions_Min_ThrowsExceptionIfStackIsEmpty()
        {
            var stack = new Stack<Int32>();

            stack.Min();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:6,代码来源:StackExtensionsTest.cs


注:本文中的Stack.Min方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。