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


C# Stack.Single方法代码示例

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


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

示例1: NumberedRepeat

        private static NFA NumberedRepeat(NFA nfa, int minRepetitions, int maxRepetitions)
        {
            // To create a suitable expression, the special case of infinite max repetitions
            // must be separately handled.
            bool infiniteMax = false;
            if (maxRepetitions == int.MaxValue)
            {
                infiniteMax = true;
                maxRepetitions = minRepetitions;
            }
            else if (maxRepetitions < minRepetitions)
            {
                maxRepetitions = minRepetitions;
            }

            // Copy the NFA max repetitions times, link them together.
            NFA output = nfa.Copy();
            var epsilonLinkStates = new Stack<NFA.State>();
            for (int i = 1; i < maxRepetitions; ++i)
            {
                NFA newNfa = nfa.Copy();
                if (i >= minRepetitions || (infiniteMax && i == maxRepetitions - 1 ))
                {
                    epsilonLinkStates.Push(newNfa.StartState);
                }
                output = And(output, newNfa);
            }

            if (infiniteMax)
            {
                // Use Single to force an exception if this has gone astray
                var finalState = epsilonLinkStates.Single();

                // Make a little epsilon loop from the final accept state to the start state of the final state
                output.Transitions.Add(new Transition<NFA.State>(output.States.Single(f => f.AcceptState), finalState));
            }
            else
            {
                // Add epsilon transitions from accept to beginning states of NFAs in the chain
                var acceptState = output.States.Single(f => f.AcceptState);
                while (epsilonLinkStates.Any())
                {
                    output.Transitions.Add(new Transition<NFA.State>(epsilonLinkStates.Pop(),
                                                                     acceptState));
                }    
            }
            

            return output;
        }
开发者ID:uptown1919,项目名称:Piglet,代码行数:50,代码来源:NfaBuilder.cs

示例2: StackExtensions_Single_ThrowsExceptionIfStackIsEmpty

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

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

示例3: StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems

        public void StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems()
        {
            var stack = new Stack<Int32>();
            stack.Push(1);
            stack.Push(2);

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

示例4: StackExtensions_Single_ReturnsSingleItemInStack

        public void StackExtensions_Single_ReturnsSingleItemInStack()
        {
            var stack = new Stack<Int32>();
            stack.Push(4);

            var result = stack.Single();

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

示例5: StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems

        public void StackExtensions_Single_ThrowsExceptionIfStackHasMultipleItems()
        {
            var stack = new Stack<Int32>();
            stack.Push(1);
            stack.Push(2);

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

示例6: StackExtensions_Single_ThrowsExceptionIfStackIsEmpty

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

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


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