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


C# Stack.IsNotEmpty方法代码示例

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


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

示例1: Parse

        /// <summary>
        /// Parses formula
        /// </summary>
        /// <param name="text">The formula's text.</param>
        /// <returns></returns>
        private List<Token> Parse(string text)
        {
            var token = new StringBuilder();
            var stack = new Stack<OperatorToken>();
            var output = new List<Token>();
            var negationPossible = true;//true if next minus means negation
            var openedBrackets = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if (char.IsDigit(text[i])
                    || text[i].ToString(Thread.CurrentThread.CurrentCulture) == Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator)
                {
                    token.Clear();
                    token.Append(text[i]);
                    while (text.Length >= i + 2 && (char.IsDigit(text[i + 1])
                        || text[i + 1].ToString(Thread.CurrentThread.CurrentCulture) == Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator))
                    {
                        token.Append(text[i + 1]);
                        ++i;
                    }

                    output.Add(new NumberToken(double.Parse(token.ToString())));
                    negationPossible = false;
                }
                else if (text[i] == '+')
                {
                    AddOperatorToStack(stack, output, new OperatorToken(OperatorType.Plus));
                    negationPossible = true;
                }
                else if (text[i] == '-')
                {
                    if (negationPossible)
                    {
                        output.Add(new NegationToken());
                        negationPossible = false;
                    }
                    else
                    {
                        AddOperatorToStack(stack, output, new OperatorToken(OperatorType.Minus));
                    }
                }
                else if (text[i] == '*')
                {
                    AddOperatorToStack(stack, output, new OperatorToken(OperatorType.Mult));
                    negationPossible = true;
                }
                else if (text[i] == '/')
                {
                    AddOperatorToStack(stack, output, new OperatorToken(OperatorType.Div));
                    negationPossible = true;
                }
                else if (text[i] == '(')
                {
                    AddOperatorToStack(stack, output, new OperatorToken(OperatorType.LeftBraket));
                    negationPossible = true;
                    openedBrackets++;
                }
                else if (text[i] == ')')
                {
                    openedBrackets--;
                    if (openedBrackets < 0)
                        return null;

                    AddOperatorToStack(stack, output, new OperatorToken(OperatorType.RightBraket));
                    negationPossible = false;
                }
                else if (char.IsLetter(text[i]))
                {
                    token.Clear();
                    token.Append(text[i]);
                    while (text.Length >= i + 2 && char.IsLetter(text[i + 1]))
                    {
                        token.Append(text[i + 1]);
                        ++i;
                    }

                    output.Add(new VariableToken(token.ToString()));
                    negationPossible = false;
                }
                else if (char.IsWhiteSpace(text[i]))
                    continue;
                else // unknown symbol in formula
                    return null;
            }

            //clear stack from operators
            while (stack.IsNotEmpty())
                output.Add(stack.Pop());

            //left and right brackets count must be equal
            if (openedBrackets != 0)
                return null;

            //in order to evaluate reverse polish notation it must be exactly one more literal than operator
//.........这里部分代码省略.........
开发者ID:kkalinowski,项目名称:lib12,代码行数:101,代码来源:Formula.cs

示例2: GetRecoverMessageFiles

        private IEnumerable<MessageFile> GetRecoverMessageFiles(long beginMessageOffset)
        {
            if (beginMessageOffset == 0L)
            {
                _logger.Info("The database does not has any messages, try to recover all the messages from all the local message log files.");
            }
            var stack = new Stack<MessageFile>();
            var messageFiles = new List<MessageFile>();
            var fileName = _setting.MessageLogFile;
            if (!new FileInfo(fileName).Exists)
            {
                _logger.InfoFormat("Message log file not exist, fileName: {0}", fileName);
                return messageFiles;
            }
            var index = 0;
            var message = GetFirstLineMessage(fileName);
            var currentFileName = fileName;
            while (message != null)
            {
                stack.Push(new MessageFile(_logger, _jsonSerializer, currentFileName));
                if (message.MessageOffset <= beginMessageOffset)
                {
                    break;
                }
                index++;
                currentFileName = fileName + "." + index;
                if (!new FileInfo(currentFileName).Exists)
                {
                    if (beginMessageOffset > 0L)
                    {
                        _logger.ErrorFormat("Message log file not exist, messages offset from [{0}] to [{1}] will not be recovered. fileName: {2}", beginMessageOffset, message.MessageOffset - 1, currentFileName);
                    }
                    break;
                }
                message = GetFirstLineMessage(currentFileName);
            }

            while (stack.IsNotEmpty())
            {
                messageFiles.Add(stack.Pop());
            }
            return messageFiles;
        }
开发者ID:YelaSeamless,项目名称:equeue,代码行数:43,代码来源:SqlServerMessageStore.cs


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