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


C# Stack.Count方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            string line = "([)]";

            char[] line2 =  line.ToCharArray();
            Stack<char> stack = new Stack<char>();
            foreach (char c in line2)
            {
                if (c == '(' || c == '{' || c == '[')
                {
                    stack.Push(c);
                }
                else if (stack.Count() != 0)
                {
                    char x = c;
                    char y = stack.Peek();
                  switch (x)
                    {
                        case ')':
                            if (y == '(')
                            {
                                stack.Pop();
                            }
                            break;
                        case ']':
                            if (y == '[')
                            {
                                stack.Pop();
                            }
                            break;
                        case '}':
                            if (y == '{')
                            {
                                stack.Pop();
                            }
                            break;
                            default:
                            break;

                    }
                }
                else
                {
                    continue;
                }

            }

                if (stack.Count() > 0)
                {
                    Console.WriteLine(false);
                }
                else
                {
                    Console.WriteLine(true);
                }
        }
开发者ID:happypoofysquirrel,项目名称:CodeEval,代码行数:57,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            IList<string> list = new List<string>() { "paper", "clip", "holder"};
            Console.WriteLine("List: {0}", string.Join(" , ", list));

            Queue<string> myQ = new Queue<string>();

            foreach (var x in list)
            {
                myQ.Enqueue(x);
            }

            Console.WriteLine("-----------------------------");

            myQ.Enqueue("pen");

            Console.WriteLine("QUEUE: {0}", string.Join(" , ", myQ));

            Stack<string> myS = new Stack<string>();

            for(int i = myQ.Count; i > 0; i--)
            {
                myS.Push(myQ.Dequeue());
            }

            Console.WriteLine("Stack: {0}", string.Join(" , ", myS));
            Console.WriteLine(myS.Count());
        }
开发者ID:Hummingdroid,项目名称:Personal-CSharp-Projects-And-Practices,代码行数:28,代码来源:Program.cs

示例3: handleTrade

        public Boolean handleTrade(Stack<string> instructions)
        {
            //Console.WriteLine(instructions);
            if (instructions.Count() == 0)
            {

            }
            else
            {
                string tradeInstr = instructions.Pop();
                APITradeType tradeType = getTradeType(tradeInstr);
                if (tradeType == APITradeType.Error)
                {

                }
                else
                {
                    switch (tradeType)
                    {
                        case APITradeType.Bank:
                            Console.WriteLine("Case Bank");
                            return bankTradeHandler.handleBankTrade(instructions);
                        case APITradeType.Harbor:
                            Console.WriteLine("Case Harbor");
                            return harborTradeHandler.handleHarborTrade(instructions);
                        case APITradeType.Player:
                            Console.WriteLine("Case Player");
                            return playerTradeHandler.handlePlayerTrade(instructions);
                    }
                }
            }
            Console.WriteLine("INVALID TRADE TYPE");
            return false;
        }
开发者ID:Lepercon5000,项目名称:socsim,代码行数:34,代码来源:TradingAPI.cs

示例4: Main

        static void Main(string[] args)
        {
            /*Write a program which implements a stack interface for integers. The interface should have ‘push’ and ‘pop’ functions.
            Your task is to ‘push’ a series of integers and then ‘pop’ and print every alternate integer.
            Print to stdout every alternate space delimited integer, one per line.
            */

            string line = "1 2 3 4"; //test input
            line.Trim();
            string[] splitLine = line.Split(' ');

            Stack<string> nums = new Stack<string>();
            foreach (string str in splitLine)
            {
                nums.Push(str);
            }

            while (nums.Count() > 0)
            {
                Console.Write(nums.Pop() + " ");
                if (nums.Count != 0)
                    { nums.Pop(); }

            }
        }
开发者ID:tbrenneison,项目名称:WCCI-Challenges,代码行数:25,代码来源:Program.cs

示例5: handleHarborTrade

        public Boolean handleHarborTrade(Stack<string> instructions)
        {
            //Format "Trade Harbor <HarborType> <ResourceWanted>
            string strHarborType;       //the type of harbor
            string strResourceType;     //the resource you want in return
            SeaHarbor harborType;
            CardType resourceType;

            if (instructions.Count() != EXPECTED_NUM_ARG)
            {
                Console.WriteLine("INVALID HARBOR TRADE ARGUMENTS");
                return false;
            }

            strHarborType = instructions.Pop();
            strResourceType = instructions.Pop();
            if (apiHelper.getHarborTypeFromString(strHarborType, out harborType)
                && (apiHelper.getResourceTypeFromString(strResourceType, out resourceType)))
            {
                Console.WriteLine("Trade will be completed " + strHarborType + " " + strResourceType + ".");
                //ARGUMENTS GOOD, Call Harbor Trading Logic
            }
            else
            {
                Console.WriteLine("INVALID HARBOR TRADE ARGUMENTS");
                return false;
            }

            return true;
        }
开发者ID:Lepercon5000,项目名称:socsim,代码行数:30,代码来源:HarborTrade.cs

示例6: handleBankTrade

        public Boolean handleBankTrade(Stack<string> instructions)
        {
            string strFourKind;     //the kind of resource you are paying 4 of.
            string strResourceType; //the kind of resource you want in return
            CardType fourKind;
            CardType resourceType;

            if (instructions.Count() != EXPECTED_NUM_ARG)
            {
                Console.WriteLine("INVALID BANK TRADE ARGUMENTS");
                return false;
            }

            strFourKind = instructions.Pop();
            strResourceType = instructions.Pop();

            if (apiHelper.getResourceTypeFromString(strFourKind, out fourKind)
                && (apiHelper.getResourceTypeFromString(strResourceType, out resourceType)))
            {
                Console.WriteLine("Trade will be completed " + strFourKind + " " + strResourceType + ".");
                //ARGUMENTS GOOD, Call Harbor Trading Logic
            }
            else
            {
                Console.WriteLine("INVALID BANK TRADE ARGUMENTS");
                return false;
            }

            return true;
        }
开发者ID:Lepercon5000,项目名称:socsim,代码行数:30,代码来源:BankTrade.cs

示例7: RestoreDeleteFiles

        bool RestoreDeleteFiles(IRepository repo)
        {
            var toExamine = new Stack<TreeEntry>(repo.Head.Tip.Tree.Where(x => x.TargetType == TreeEntryTargetType.Tree));
            var files = new List<TreeEntry>();
            files.AddRange(repo.Head.Tip.Tree.Where(x => x.TargetType == TreeEntryTargetType.Blob));

            while (toExamine.Count() != 0)
            {
                var next = (Tree)toExamine.Pop().Target;
                files.AddRange(next.Where(x => x.TargetType == TreeEntryTargetType.Blob));
                foreach (var t in next.Where(x => x.TargetType == TreeEntryTargetType.Tree))
                    toExamine.Push(t);
            }

            var deleted = files.Select(x => x.Path).Where(x => !File.Exists(Path.Combine(_repoDir, x)));

            if (deleted.Any())
            {
                Console.WriteLine("Restoring deleted files");
                repo.CheckoutPaths(repo.Head.Tip.Sha, deleted,
                    new CheckoutOptions
                    {
                        CheckoutModifiers = CheckoutModifiers.Force,
                        CheckoutNotifyFlags = CheckoutNotifyFlags.Dirty,
                        OnCheckoutNotify = (s, f) => { Console.WriteLine("Restoring {0}", s); return true; }
                    });
                return true;
            }

            return false;
        }
开发者ID:Xcelled,项目名称:aura-frontend,代码行数:31,代码来源:UpdateSource.cs

示例8: StackCount

 public void StackCount()
 {
     var stack = new Stack<int>();
     stack.Push(2);
     stack.Push(3);
     Assert.AreEqual(2, stack.Count());
 }
开发者ID:anton-christensen,项目名称:p2_software,代码行数:7,代码来源:QueueStackandCloneTests.cs

示例9: PreorderTraversal

        public IList<int> PreorderTraversal(TreeNode root)
        {
            var re = new List<int>();
            if (root == null)
                return re;

            var st = new Stack<TreeNode>();

            st.Push(root);
            re.Add(root.val);
            while (root.left != null)
            {
                root = root.left;
                st.Push(root);
                re.Add(root.val);
            }
            while (st.Count() > 0)
            {
                var node = st.Pop();

                var right = node.right;

                while (right != null)
                {
                    st.Push(right);
                    re.Add(right.val);
                    right = right.left;
                }
            }

            return re;
        }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:32,代码来源:Solution144.cs

示例10: Main

        static void Main(string[] args)
        {
            string line = ("1 2 3 4 5 6");

             string[] line2= line.Split(' ');  //splitting the line into character

            Stack<string> numStack = new Stack<string>();

            foreach (string value in line2)  //converting and pushing each number onto the stack
            {

                numStack.Push(value);

            }
            int x = 1;
            while (x != 0)
            {
                Console.Write(numStack.Pop() + " ");
                if (numStack.Count !=0)
                {
                    numStack.Pop();
                }

                x = numStack.Count();
            }
            Console.WriteLine();
        }
开发者ID:happypoofysquirrel,项目名称:CodeEval,代码行数:27,代码来源:Program.cs

示例11: Main

        static void Main()
        {
            Console.WriteLine("Enter several integers, separated by a space:");
            var inputString = Console.ReadLine().TrimEnd(' ');
            var inputArray = inputString.Split(' ');
            var numbersStack = new Stack<int>();

            int currentInt;
            bool result = true;

            for (int i = 0; i < inputArray.Length; i++)
            {
                result = Int32.TryParse(inputArray[i], out currentInt);

                if (!result)
                {
                    Console.WriteLine("Empty or invalid number!");
                    break;
                }
                numbersStack.Push(currentInt);
            }

            if (result)
            {
                var numbersStackCount = numbersStack.Count();
                
                for (int i = 0; i < numbersStackCount; i++)
                {
                    Console.Write(numbersStack.Pop().ToString()+' ');
                }
            }
        }
开发者ID:anichalakova,项目名称:DataStructuresHWs,代码行数:32,代码来源:Program.cs

示例12: DFS

        public void DFS( List<List<Peg>> start, List<List<Peg>> goal, Graph graph)
        {
            nodeComparer nComp = new nodeComparer();
            Dictionary<List<List<Peg>>, List<List<Peg>>> parent = new Dictionary<List<List<Peg>>, List<List<Peg>>>(nComp);
            Stack<List<List<Peg>>> stack = new Stack<List<List<Peg>>>();
            stack.Push(start);
            parent.Add(start, null);
            List<List<Peg>> current = null;
            while(stack.Count() != 0)
            {
                current = stack.Pop();
                if (current == goal || current.SequenceEqual(goal) || nComp.Equals(current,goal)) break;

                foreach (EdgeInfo ef in graph.nodes[current].adjacent)
                {
                    if (!parent.ContainsKey(ef.goesTo))
                    {
                        parent.Add(ef.goesTo, current);
                        stack.Push(ef.goesTo);
                    }
                }
            }
            if (current == goal || current.SequenceEqual(goal) || nComp.Equals(current, goal))
            {
                bool first = true;
                int left = 0;
                int top = 0;
                this.label1.Text = "Solution found!!";
                this.button1.Text = "Close";
                //goal
                this.label2.Text = triangle.printBoard(goal) + "<====";
                List<List<Peg>> from = parent[goal];

                while (from != null)
                {
                    Label nLabel = new Label();
                    nLabel.AutoSize = true;
                    if(first)
                    {
                        nLabel.Top = this.label2.Top;
                        nLabel.Left = this.label2.Left + this.label2.Width + 5;
                        first = false;
                    }
                    else
                    {
                        nLabel.Top = top;
                        nLabel.Left = left;
                    }
                    nLabel.Text += triangle.printBoard(from) + "<====";
                    this.panel1.Controls.Add(nLabel);
                    from = parent[from];
                    left = nLabel.Left + nLabel.Width + 5;
                    top = nLabel.Top;
                }
            }
            else
            {
                this.label2.Text = "goal not reachable";
            }
        }
开发者ID:HeKnOw,项目名称:PegPuzzle,代码行数:60,代码来源:Form1.cs

示例13: ReadPassword

 public static string ReadPassword()
 {
     var passbits = new Stack<string>();
     //keep reading
     for (ConsoleKeyInfo cki = Console.ReadKey(true); cki.Key != ConsoleKey.Enter; cki = Console.ReadKey(true))
     {
         if (cki.Key == ConsoleKey.Backspace)
         {
             if (passbits.Count() > 0)
             {
                 //rollback the cursor and write a space so it looks backspaced to the user
                 Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                 Console.Write(" ");
                 Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                 passbits.Pop();
             }
         }
         else
         {
             Console.Write("*");
             passbits.Push(cki.KeyChar.ToString());
         }
     }
     string[] pass = passbits.ToArray();
     Array.Reverse(pass);
     Console.Write(Environment.NewLine);
     return string.Join(string.Empty, pass);
 }
开发者ID:RobThree,项目名称:RedditSharp,代码行数:28,代码来源:Program.cs

示例14: Initialize

 public void Initialize(string filename, int munitionMax, Stack<Munitions> munitionLoaded, Player hero, ContentManager Content)
 {
     munitionLoaded = new Stack<Munitions>();
     for (int i = 0; i < munitionMax; i++)
     {
         munitionLoaded.Push(new Munitions(new Rectangle(0, 0, 0, 0), Content.Load<Texture2D>(filename), hero.Direction, 31, 31));
     }
     munitionLeft = munitionLoaded.Count();
 }
开发者ID:Jh87S,项目名称:TLN,代码行数:9,代码来源:Munitions.cs

示例15: MaxArray2

        int[] MaxArray2(int[] num, int len)
        {
            int drop = num.Length - len;

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

            foreach(var d in num)
            {
                while (st.Count() > 0 && drop > 0 && d > st.Peek())
                {
                    st.Pop();
                    drop--;
                }
                st.Push(d);
            }

            return st.Skip(st.Count() - len).Reverse().ToArray();            
        }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:18,代码来源:Solution321.cs


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