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


C# Stack.Last方法代码示例

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


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

示例1: GetBracketMismatch

        //Returns the location of bracket mismatch
        //Rewrite this to make use of better suited container for brackets
        public int GetBracketMismatch(string code)
        {
            Dictionary<char, char> bracketMap = new Dictionary<char, char>()
            { {'{', '}'}, {'(', ')'}, {'[', ']'}, {'<', '>'} };//, {'\'', '\''} }; //{} () [] <> "" ''
            Stack<char> bracketStack = new Stack<char>();
            int counter = 0;

            foreach (char c in code)
            {
                if("(){}<>".Contains(c))
                {
                    if (!")}>".Contains(c))
                    {
                        bracketStack.Push(c);
                    }
                    else if (bracketMap.Any(q => q.Key == bracketMap[bracketStack.Last()]))
                    {
                        bracketStack.Pop();
                    }
                    else
                    {
                        return counter;
                    }
                }
                counter++;
            }

            return -1;
        }
开发者ID:remco138,项目名称:amanda,代码行数:31,代码来源:Tags.cs

示例2: Main

 static void Main()
 {
     string input = Console.ReadLine();
     if (input.Equals(""))
     {
         Console.WriteLine("(empty)");
         return;
     }
     string[] charinp = input.Split(' ');
     int index = 0;
     Stack<int> resiver = new Stack<int>();
     for (int i = 0; i < charinp.Length; i++)
     {
         if (!int.TryParse(charinp[i], out index))
         {
             Console.WriteLine("Invalid Input");
             return;
         }
         resiver.Push(index);
     }
       while(resiver.Count>1)
     {
         int j = resiver.Pop();
         Console.Write(j+" ");
     }
       Console.WriteLine(resiver.Last());
 }
开发者ID:kosio197,项目名称:SoftUni_DataStructures,代码行数:27,代码来源:ReverseStack.cs

示例3: GetSuperTypes

 protected virtual void GetSuperTypes(List<Interface> superTypes, Stack<Interface> branch, bool throws = false)
 {
     branch.Push(this);
     foreach (Interface superType in this.SuperInterfaces)
     {
         // Circular inheritance condition
         if (!branch.Contains(superType))
         {
             // Multiple-path inheritance condition
             if (!superTypes.Contains(superType))
             {
                 superTypes.Add(superType);
                 superType.GetSuperTypes(superTypes, branch, throws);
             }
         }
         else
         {
             if (throws)
             {
                 throw new InheritanceValidationException(branch.Last());
             }
         }
     }
     branch.Pop();
 }
开发者ID:st9200,项目名称:soal-oslo,代码行数:25,代码来源:Interface.cs

示例4: Main

        static void Main(string[] args)
        {
            Stack s = new Stack();

            string temp = Console.ReadLine();
            int a;
            int b;
            char x;

            for (var i = 0; i <= temp.Length - 1; i++)
            {
                if ((temp[i] >= '0') && (temp[i] <= '9'))
                {
                    int j = 0;
                    while ((temp[i + j] >= '0') && (temp[i + j] <= '9'))
                    {
                        j++;
                    }

                    string str = temp.Substring(i, j);
                    int k = int.Parse(str);
                    s.Add(k);
                    i = i + j-1;
                }
                else if (temp[i] == ')')
                {
                    b = (int)s.Last();
                    s.Remove();
                    x = (char)s.Last();
                    s.Remove();
                    a = (int)s.Last();
                    s.Remove();
                    s.Remove();
                    int Rez = Solve(a, b, x);
                    s.Add((object)Rez);
                }
                else
                {
                    s.Add(temp[i]);
                }

            }
                Console.WriteLine(s.Last());
        }
开发者ID:Elta20042004,项目名称:Training,代码行数:44,代码来源:Program.cs

示例5: CombinePath

        private static string CombinePath(Stack<string> path)
        {
            var parts = new List<string>(3);

            parts.Add(path.First());

            if (path.Count > 1)
            {
                if (path.Count > 2)
                {
                    parts.Add("..");
                }

                parts.Add(path.Last());
            }

            return string.Join(Path.DirectorySeparatorChar.ToString(), parts);
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:18,代码来源:FileNamer.cs

示例6: EmitSSAforArrayDimension

        /// <summary>
        /// Emits the SSA form of each dimension in the ArrayNode data structure
        /// The dimensionNode is updated by the function with the SSA'd dimensions
        /// 
        /// Given:
        ///     dimensionNode -> a[b][c] 
        /// Outputs:
        ///     astlist -> t0 = b
        ///             -> t1 = c
        ///     dimensionNode -> a[t0][t1] 
        ///     
        /// </summary>
        /// <param name="dimensionNode"></param>
        /// <param name="astlist"></param>
        private void EmitSSAforArrayDimension(ref ArrayNode dimensionNode, ref List<AssociativeNode> astlist)
        {
            AssociativeNode indexNode = dimensionNode.Expr;

            // Traverse first dimension
            Stack<AssociativeNode> localStack = new Stack<AssociativeNode>();
            DFSEmitSSA_AST(indexNode, localStack, ref astlist);

            AssociativeNode tempIndexNode = localStack.Last();
            if (tempIndexNode is BinaryExpressionNode)
            {
                dimensionNode.Expr = (tempIndexNode as BinaryExpressionNode).LeftNode;

                // Traverse next dimension
                indexNode = dimensionNode.Type;
                while (indexNode is ArrayNode)
                {
                    ArrayNode arrayNode = indexNode as ArrayNode;
                    localStack = new Stack<AssociativeNode>();
                    DFSEmitSSA_AST(arrayNode.Expr, localStack, ref astlist);
                    tempIndexNode = localStack.Last();
                    if (tempIndexNode is BinaryExpressionNode)
                    {
                        arrayNode.Expr = (tempIndexNode as BinaryExpressionNode).LeftNode;
                    }
                    indexNode = arrayNode.Type;
                }
            }
        }
开发者ID:AutodeskFractal,项目名称:Dynamo,代码行数:43,代码来源:CodeGen.cs

示例7: TryEvaluate

 internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
 {
     if (_next == null)
       {
     context = contextStack.Last();
     return true;
       }
       else
       {
     var rootedContextStack = new Stack<Context>();
     rootedContextStack.Push(contextStack.Last());
     return _next.TryEvaluate(rootedContextStack, state, out context);
       }
 }
开发者ID:Noxum,项目名称:CompiledHandlebars,代码行数:14,代码来源:Identifier.cs

示例8: GetFileInfoFiles

        public static IEnumerable<FileInfo> GetFileInfoFiles(string root, string fileExt)
        {
            Stack<string> pending = new Stack<string>();
            pending.Push(root);
            DirectoryInfo direcInfo = new DirectoryInfo(root);
            while (pending.Count < 2 && pending.Count != 0)
            {
                var path = pending.Pop();
                FileInfo[] next = null;
                try
                {
                    next = direcInfo.GetFiles(fileExt);

                }
                catch { }
                if (next != null && next.Length != 0)
                    foreach (var file in next) yield return file;
                try
                {
                    next = direcInfo.GetFiles(fileExt);
                    foreach (var subdir in next)
                    //pending.Push(subdir.FullName);
                    {
                        if (pending.Last() != subdir.FullName)
                            pending.Push(subdir.FullName);
                    }
                }
                catch { }
            }
        }
开发者ID:SundeepK,项目名称:Geom,代码行数:30,代码来源:FileBrowserScreen.cs

示例9: GetFiles

        public IEnumerable<string> GetFiles(string root)
        {
            Stack<string> pending = new Stack<string>();
            pending.Push(root);
            while (pending.Count < 4 && pending.Count != 0)
            {
                var path = pending.Pop();
                string[] next = null;
                try
                {
                    next = Directory.GetDirectories(path);

                }
                catch { }
                if (next != null && next.Length != 0)
                    foreach (var file in next) yield return file;
                try
                {
                    next = Directory.GetDirectories(path);
                    foreach (var subdir in next)
                    //pending.Push(subdir);
                    {
                        if (pending.Last() != subdir)
                            pending.Push(subdir);
                    }
                }
                catch { }
            }
        }
开发者ID:SundeepK,项目名称:Geom,代码行数:29,代码来源:FileBrowserScreen.cs

示例10: StackExtensions_Last_ThrowsExceptionIfStackIsEmpty

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

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

示例11: StackExtensions_Last_ReturnsLastItemInStack

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

            var result = stack.Last();

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

示例12: StackExtensions_Last_ThrowsExceptionIfStackIsEmpty

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

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

示例13: ParseTree

        private static Haplogroup ParseTree(string filename)
        {
            var flatTree = ParseFlatTree(filename);
            var stack = new Stack<Haplogroup>();

            stack.Push(new Haplogroup() { Name = flatTree.First().Key });

            Action<string> add = x =>
            {
                var g = new Haplogroup()
                {
                    Name = x,
                    Parent = stack.Peek(),
                };
                stack.Peek().Children.Add(g);
                stack.Push(g);
            };

            var depth = 0;
            var filler = 0;

            foreach (var node in flatTree.Skip(1))
            {
                if (node.Value == depth)
                {
                    stack.Pop();
                    add(node.Key);
                }
                //else if (node.Value == depth + 1)
                else if (node.Value > depth)

                {
                    var delta = node.Value - depth;
                    depth += delta;

                    foreach (var f in Enumerable.Range(0, delta - 1))
                    {
                        add("FILLER_" + filler++);
                    }

                    add(node.Key);
                }
                //else if (node.Value > depth)
                //{
                //    Console.WriteLine();
                //}
                else
                {
                    var delta = depth - node.Value;
                    depth -= delta;

                    for (var i = 0; i < delta + 1; i++)
                    {
                        stack.Pop();
                    }

                    add(node.Key);
                }
            }

            return stack.Last();
        }
开发者ID:John-Leitch,项目名称:GenomeDotNet,代码行数:62,代码来源:Program.cs


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