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


C# Stack.Any方法代码示例

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


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

示例1: SplitWithIgnoreRegions

 public static IEnumerable<string> SplitWithIgnoreRegions(this string s, char[] separators, params IgnoreRegion[] ignoreregions)
 {
     if (separators == null) {
     throw new ArgumentNullException("separators");
       }
       if (ignoreregions == null || !ignoreregions.Any()) {
     throw new ArgumentNullException("ignoreregions");
       }
       if (!string.IsNullOrWhiteSpace(s)) {
     Stack<char> irStack = new Stack<char>();
     var splitted = new List<string>();
     string tmp = string.Empty;
     foreach (char c in s) {
       var irMatch = ignoreregions.FirstOrDefault(ir => ir.Start == c);
       if (irStack.Any() && irStack.Peek() == c) {
     // found end of ignoreregion, remove last region info
     irStack.Pop();
     tmp += c;
       } else if (irMatch != null) {
     // found start of ignoreregion
     irStack.Push(irMatch.End);
     tmp += c;
       } else if (separators.Any(sep => sep == c) && !irStack.Any()) {
     // found valid separator, do split, but check if there are pending ignore regions in stack
     splitted.Add(tmp);
     tmp = string.Empty;
       } else {
     tmp += c;
       }
     }
     splitted.Add(tmp);
     return splitted;
       }
       return Enumerable.Empty<string>();
 }
开发者ID:vipwolf,项目名称:moni,代码行数:35,代码来源:StringParserHelper.cs

示例2: Calc

        public Item Calc(int[] program)
        {
            var stack = new Stack<Item>();
            for (long i = 0; i < program.Length; i++)
            {
                if (program[i] == 0)
                {
                    Item temp = new Item();
                    if (stack.Any())
                        temp.Add(stack.Pop());
                    if (stack.Any())
                        temp.Add(stack.Pop());

                    stack.Push(temp);
                }
                else if (program[i] == -1)
                {
                    stack.Push(new Item(0, 1));
                }
                else
                    stack.Push(new Item(program[i], 0));
            }

            return stack.Pop();
        }
开发者ID:analyst74,项目名称:TopCoder,代码行数:25,代码来源:Suminator.cs

示例3: IterativePostOrder

        /** Iteratively traverses the binary tree in post-order */
        public void IterativePostOrder(TreeNode root)
        {
            if (root == null) return;

            Stack<TreeNode> stack = new Stack<TreeNode>();
            TreeNode current = root;

            while (true)
            {

                if (current != null)
                {
                    if (current.Right != null) stack.Push(current.Right);
                    stack.Push(current);
                    current = current.Left;
                    continue;
                }

                if (!stack.Any()) return;
                current = stack.Pop();

                if (current.Right != null && stack.Any() && current.Right == stack.Peek())
                {
                    stack.Pop();
                    stack.Push(current);
                    current = current.Right;
                }
                else
                {
                    Debug.Write(current.Data + " ");
                    current = null;
                }
            }
        }
开发者ID:ajaydhawan,项目名称:algorithm-solutions,代码行数:35,代码来源:Traversals.cs

示例4: DumpFullStack

 private static void DumpFullStack(Stack<string> stack, ICollection<string> postfix)
 {
     while (stack.Any() && stack.Any())
     {
         postfix.Add(stack.Pop());
     }
 }
开发者ID:agabani,项目名称:MathExpressionEvaluator,代码行数:7,代码来源:Notation.cs

示例5: ComputeLargetArea

    static int ComputeLargetArea(int[] hist)
    {
        var stack = new Stack<int>();
        var max = 0;

        var i = 0;
        while (i < hist.Length)
        {
            if (!stack.Any() || hist[stack.Peek()] <= hist[i])
            {
                stack.Push(i);
                i++;
            }
            else
            {
                max = ComputeStack(hist, stack, max, i);
            }
        }

        while (stack.Any())
        {
            max = ComputeStack(hist, stack, max, i);
        }

        return max;
    }
开发者ID:Crazy7,项目名称:HackerRank,代码行数:26,代码来源:Program.cs

示例6: DumpUntilOpenParentheses

 private static void DumpUntilOpenParentheses(Stack<string> stack, ICollection<string> postfix)
 {
     while (stack.Any() && !IsOpenParentheses(stack.Peek()))
     {
         postfix.Add(stack.Pop());
     }
 }
开发者ID:agabani,项目名称:MathExpressionEvaluator,代码行数:7,代码来源:Notation.cs

示例7: VerifyPreorder

    public bool VerifyPreorder(int[] preorder)
    {
        if(preorder == null || preorder.Length <= 2){ return true; }

        var s = new Stack<int>();
        s.Push(preorder[0]);
        var min = int.MinValue;
        for(int i = 1; i < preorder.Length; i++){
            var curr = preorder[i];

            if(curr<=min){ return false;}

            var parent = s.Peek();

            if(curr > parent){
                while(curr > parent){
                    min = s.Pop();
                    parent = s.Any() ? s.Peek() : int.MaxValue;
                }
            }

            s.Push(curr);
        }

        return true;
    }
开发者ID:WillFr,项目名称:train,代码行数:26,代码来源:Solution+I.cs

示例8: GetItemsRecursively

        private static List<Item> GetItemsRecursively(Item item, int attributeId)
        {
            var itemStack = new Stack<Item>();
            itemStack.Push(item);

            var selectedItems = new List<Item>();

            while (itemStack.Any())
            {
                var curItem = itemStack.Pop();
                if (curItem is Skill)
                {
                    continue; //TODO das ist haesslich evtl. anders loesen
                }
                foreach (var subItem in curItem.InstalledItems)
                {
                    if (subItem is Skill)
                    {
                        continue;
                    }
                    //TODO index attributes by id -> faster lookup
                    foreach (var curSkillRequirementId  in SKILL_REQUIREMENT_ATTRIBUTE_IDS)
                    {
                        IAttribute attribute;
                        if (subItem.TryGetAttributeById(curSkillRequirementId, out attribute) && (int) attribute.Value == attributeId)
                        {
                            selectedItems.Add(subItem);
                            break;
                        }
                    }
                    itemStack.Push(subItem);
                }
            }
            return selectedItems;
        }
开发者ID:rischwa,项目名称:eve-fast-fitting-assessment,代码行数:35,代码来源:LocationAndSkillRequirementSelectorExpression.cs

示例9: CreateGraphOfPipeSystem

        private static IVertexAndEdgeListGraph<PipeGraphVertex, Edge<PipeGraphVertex>> CreateGraphOfPipeSystem(PipeGraphVertex firstVertex)
        {
            var graph = new AdjacencyGraph<PipeGraphVertex, Edge<PipeGraphVertex>>(false);
            var verticesSeen = new HashSet<PipeGraphVertex>();
            var verticesToCheck = new Stack<PipeGraphVertex>();
            verticesToCheck.Push(firstVertex);

            while (verticesToCheck.Any())
            {
                var vertexToCheck = verticesToCheck.Pop();
                if (verticesSeen.Contains(vertexToCheck)) continue;

                var sendsTo = GetVerticesYouSendMessagesTo(vertexToCheck);
                var receivesFrom = GetVerticesYouReceiveMessagesFrom(vertexToCheck);

                foreach (var vertex in sendsTo) verticesToCheck.Push(vertex);
                foreach (var vertex in receivesFrom) verticesToCheck.Push(vertex);

                graph.AddVertex(vertexToCheck);

                graph.AddVerticesAndEdgeRange(sendsTo.Select(v => new Edge<PipeGraphVertex>(vertexToCheck, v)));
                graph.AddVerticesAndEdgeRange(receivesFrom.Select(v => new Edge<PipeGraphVertex>(v, vertexToCheck)));

                verticesSeen.Add(vertexToCheck);
            }

            return graph;
        }
开发者ID:michaelbradley91,项目名称:Pipes,代码行数:28,代码来源:PipeExtensions.cs

示例10: Run

        public void Run(ref IGrid grid)
        {
            var startAt = grid.GetRandomCell;
            active = new Stack<Cell>();
            active.Push(startAt);

            costs = new Dictionary<Cell, int>();
            foreach(var cell in grid)
            {
                costs[cell] = GetRandomNumber(0, 100);
            }

            int iterations = 1;
            while(active.Any())
            {
                iterations++;
                var cell = Min(active);  // Get the minimum value in the *active* set
                var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0);

                if (availableNeighbors.Any())
                {
                    var neighbor = Min(availableNeighbors); // Get the minimum value in the *availableNeighbors* set
                    cell.Link(neighbor);
                    active.Push(neighbor);
                }
                else
                {
                    var list = active.ToList();
                    list.Remove(cell);
                    active = new Stack<Cell>(list);
                }
            }
            Console.WriteLine($"Iterations: {iterations}");
        }
开发者ID:davidjeet,项目名称:MazesCSharp,代码行数:34,代码来源:TruePrim.cs

示例11: GetAllProjects

        /// <summary>
        /// Get the list of all supported projects in the current solution. This method
        /// recursively iterates through all projects.
        /// </summary>
        public static IEnumerable<Project> GetAllProjects(this Solution solution)
        {
            if (solution == null || !solution.IsOpen) {
                yield break;
            }

            var projects = new Stack<Project>();
            foreach (Project project in solution.Projects) {
                projects.Push(project);
            }

            while (projects.Any()) {
                Project project = projects.Pop();

                if (project.IsSupported()) {
                    yield return project;
                }

                // ProjectItems property can be null if the project is unloaded
                if (project.ProjectItems != null) {
                    foreach (ProjectItem projectItem in project.ProjectItems) {
                        if (projectItem.SubProject != null) {
                            projects.Push(projectItem.SubProject);
                        }
                    }
                }
            }
        }
开发者ID:grendello,项目名称:nuget,代码行数:32,代码来源:SolutionExtensions.cs

示例12: GetAllLinksFromSite

        public string[] GetAllLinksFromSite(string baseSite, int maxSites = 100)
        {
            HashSet<string> hasLink = new HashSet<string>();
            List<string> result = new List<string>();
            Stack<string> sitesToVisit = new Stack<string>();

            sitesToVisit.Push(baseSite);
            result.Add(baseSite);
            hasLink.Add(baseSite);

            while (sitesToVisit.Any())
            {
                // New site to visit
                var site = sitesToVisit.Pop();

                var links = GetLinksFromSite(site);

                foreach (var link in links)
                {
                    if (!hasLink.Contains(link))
                    {
                        hasLink.Add(link);
                        result.Add(link);
                        sitesToVisit.Push(link);

                        if (result.Count == maxSites)
                        {
                            return result.ToArray();
                        }
                    }
                }
            }

            return result.ToArray();
        }
开发者ID:Rfaering,项目名称:TextAnalysis,代码行数:35,代码来源:WebSiteCrawler.cs

示例13: Run

        public void Run(ref IGrid grid)
        {
            var startAt = grid.GetRandomCell;
            Stack<Cell> active = new Stack<Cell>();
            active.Push(startAt);
            int iterations = 1;
            while(active.Any())
            {
                iterations++;
                var cell = active.Sample();
                var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0);

                if (availableNeighbors.Any())
                {
                    var neighbor = availableNeighbors.Sample();
                    cell.Link(neighbor);
                    active.Push(neighbor);
                }
                else
                {
                    var list = active.ToList();
                    list.Remove(cell);
                    active = new Stack<Cell>(list);
                }
            }
            Console.WriteLine($"Iterations: {iterations}");
        }
开发者ID:davidjeet,项目名称:MazesCSharp,代码行数:27,代码来源:SimplifiedPrim.cs

示例14: Dimensionalize

        private static IRvalueConstruct Dimensionalize(Stack<object> stack)
        {
            Contract.Requires(stack.Any());

            var next = stack.Pop();
            if (next is IRvalueConstruct)
                return next as IRvalueConstruct;
            if (next is ResolvedToken) {
                switch ((next as ResolvedToken).Type) {
                    case Token.OP_ADDITION:
                        return new AdditionConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    case Token.OP_DIVISION:
                        return new DivisionConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    case Token.OP_EXPONENT:
                        return new ExponentConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    case Token.OP_SUBTRACTION:
                        return new SubtractionConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    case Token.OP_MODULO:
                        return new ModuloConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    case Token.OP_MULTIPLICATION:
                        return new MultiplicationConstruct(Dimensionalize(stack), Dimensionalize(stack));
                    default:
                        throw new LexerException(ErrorCode.ErrorForCode("LEX3"));
                }
            }
            throw new LexerException(ErrorCode.ErrorForCode("LEX3"));
        }
开发者ID:poskadesign,项目名称:CS-S7-Compiler-Theory,代码行数:27,代码来源:PolishNotation.cs

示例15: InfixToPrefix

        public static IRvalueConstruct InfixToPrefix(ICollection<object> construct)
        {
            if (construct.Count == 1)
                return construct.First() as IRvalueConstruct;

            var output = new Stack<object>();
            var operators = new Stack<object>();

            // separate rvalues and operators
            foreach (var c in construct) {
                if (c is IRvalueConstruct)
                    output.Push(c);
                else if (c is ResolvedToken) {
                    if (operators.Any() && RL.OperatorPrecedence((c as ResolvedToken).Type) < RL.OperatorPrecedence((operators.Peek() as ResolvedToken).Type)) {
                        Merge(output, operators);
                    }
                    operators.Push(c);
                }

            }

            // merge to prefix notation
            Merge(output, operators);

            return Dimensionalize(output);
        }
开发者ID:poskadesign,项目名称:CS-S7-Compiler-Theory,代码行数:26,代码来源:PolishNotation.cs


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