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


C# Stack.Contains方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            Stack<int> numbers = new Stack<int>();

            numbers.Push(4);
            numbers.Push(5);
            numbers.Push(5);
            numbers.Push(6);
            numbers.Push(7);
            numbers.Push(2);
            numbers.Push(22);
            numbers.Push(33);
            numbers.Push(14);
            Console.WriteLine(numbers.Count);

            Console.WriteLine(numbers.Pop());
            Console.WriteLine(numbers.Pop());
            Console.WriteLine(numbers.Peek());
            Console.WriteLine(numbers.Count);

            Console.WriteLine(numbers.Contains(5));
            Console.WriteLine(numbers.Contains(55));

            numbers.Clear();
            numbers.Push(44);
            Console.WriteLine(numbers.Count);
        }
开发者ID:Gardax,项目名称:CSharpExercises,代码行数:27,代码来源:Program.cs

示例2: Main

        static void Main()
        {
            int[] inputNums = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse).ToArray();
            int[] array = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse).ToArray();
            var stack = new Stack<int>();
            for (int i = 0; i < array.Length; i++)
            {
                stack.Push(array[i]);
            }

            for (int i = 0; i < inputNums[1]; i++)
            {
                stack.Pop();
            }

            if (stack.Contains(inputNums[2]))
            {
                Console.WriteLine("true");
            }
            else if (!stack.Contains(inputNums[2]) && stack.Count > 0)
            {
                Console.WriteLine(stack.Min());
            }
            else
            {
                Console.WriteLine(0);
            }
        }
开发者ID:Razkolnikow,项目名称:AdvancedCSharpHomeWorks,代码行数:30,代码来源:Program.cs

示例3: BuildOperation

 /// <summary>
 /// Build the current operation in the <see cref="QueryExecutionPlan"/> by reading the abstract syntax tree.
 /// </summary>
 /// <param name="scope">Scope of the current <see cref="ParseTreeNode"/>.</param>
 /// <param name="node">Current <see cref="ParseTreeNode"/> in the abstract syntax tree.</param>
 /// <param name="plan">The current <see cref="QueryExecutionPlan"/> being built.</param>
 public void BuildOperation(Stack<string> scope, ParseTreeNode node, QueryExecutionPlan plan)
 {
     if (node.Term.Name == "selectStmt")
     {
         // Select clause
         plan.Operations.Add(new LevelDbSelectOperation());
     }
     else if (scope.Contains("selList") && node.Term.Name == "id_simple")
     {
         // Select column list
         plan.Current.ColumnNames.Add(node.Token.ValueString);
     }
     else if (scope.Contains("selList") && node.Term.Name == "*")
     {
         // Select column list
         plan.Current.ColumnNames.Add(node.Token.ValueString);
     }
     else if (scope.Contains("fromClauseOpt") && node.Term.Name == "id_simple")
     {
         // From clause
         plan.Current.TableName = node.Token.ValueString;
     }
     else if (scope.Contains("whereClauseOpt") && node.Term.Name == "binExpr")
     {
         // Where clause
         var column = node.ChildNodes[0].ChildNodes[0].Token.ValueString;
         var val = node.ChildNodes[2].Token.ValueString;
         plan.Current.WhereClauses.Add(column, val);
     }
 }
开发者ID:pedroreys,项目名称:Dazzle,代码行数:36,代码来源:SelectOperationBuilder.cs

示例4: ContainsUsesEqualsMethod

		public void ContainsUsesEqualsMethod() {
			var s = new Stack<C>();
			s.Push(new C(1));
			s.Push(new C(2));
			s.Push(new C(3));
			Assert.IsTrue(s.Contains(new C(2)));
			Assert.IsFalse(s.Contains(new C(4)));
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:8,代码来源:StackTests.cs

示例5: Main

 static void Main(string[] args)
 {
     int[] integers = { 1, 2, 3, 4, 5 };
     LinkedList<int> list = new LinkedList<int>(integers);
     Stack<int> obj = new Stack<int>(list);
     Console.WriteLine(obj.Contains(4));
     Dequeue<int> newObj = new Dequeue<int>(list);
     Console.WriteLine(obj.Contains(7));
 }
开发者ID:vanka7aflame,项目名称:HackBulgariaCsharp,代码行数:9,代码来源:Program.cs

示例6: ContainsWorks

		public void ContainsWorks() {
			var s = new Stack<int>();
			s.Push(10);
			s.Push(2);
			s.Push(4);
			Assert.IsTrue(s.Contains(10));
			Assert.IsTrue(s.Contains(2));
			Assert.IsFalse(s.Contains(11));
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:9,代码来源:StackTests.cs

示例7: Stack_Contains_ContainsMustReturnTrue

        public void Stack_Contains_ContainsMustReturnTrue()
        {
            var stack = new Stack<int>();
            int[] mass = { 73, 3, 7, 37 };
            for (int i = 0; i < mass.Length; ++i)
                stack.Push(mass[i]);

            bool actual = stack.Contains(73);
            Assert.AreEqual(true, actual);

            actual = stack.Contains(703);
            Assert.AreEqual(false, actual);
        }
开发者ID:GrimRanger,项目名称:Stack,代码行数:13,代码来源:StackTest.cs

示例8: Stack_Contains_ContainsWithNull

        public void Stack_Contains_ContainsWithNull()
        {
            var stack = new Stack<string>();
            string[] mass = { "34", "cartoon", "raccoon", "joke", null };
            for (int i = 0; i < mass.Length; ++i)
                stack.Push(mass[i]);

            bool actual = stack.Contains(null);
            Assert.AreEqual(true, actual);

            actual = stack.Contains("joke");
            Assert.AreEqual(true, actual);
        }
开发者ID:GrimRanger,项目名称:Stack,代码行数:13,代码来源:StackTest.cs

示例9: BuildOperation

        /// <summary>
        /// Build the current operation in the <see cref="QueryExecutionPlan"/> by reading the abstract syntax tree.
        /// </summary>
        /// <param name="scope">Scope of the current <see cref="ParseTreeNode"/>.</param>
        /// <param name="node">Current <see cref="ParseTreeNode"/> in the abstract syntax tree.</param>
        /// <param name="plan">The current <see cref="QueryExecutionPlan"/> being built.</param>
        public void BuildOperation(Stack<string> scope, ParseTreeNode node, QueryExecutionPlan plan)
        {
            if (node.Term.Name == this.OperationName)
            {
                // Select clause
                plan.Operations.Add(new SelectOperation());
            }

            var operation = (SelectOperation)plan.Current;

            if (scope.Contains("selList") && node.Term.Name == "id_simple")
            {
                // Select column list
                operation.ColumnNames.Add(node.Token.ValueString);
            }
            else if (scope.Contains("selList") && node.Term.Name == "*")
            {
                // Select column list
                operation.ColumnNames.Add(node.Token.ValueString);
            }
            else if (scope.Contains("fromClauseOpt") && node.Term.Name == "id_simple")
            {
                // From clause
                operation.TableName = node.Token.ValueString;
            }
            else if (scope.Contains("whereClauseOpt") && node.Term.Name == "binExpr")
            {
                // Where clause
                if (node.ChildNodes[0].Term.Name == "binExpr")
                {
                    // Handle multiple where clauses.
                    foreach (var child in node.ChildNodes)
                    {
                        if (child.Term.Name == "binExpr")
                        {
                            var column = child.ChildNodes[0].ChildNodes[0].Token.ValueString;
                            var val = child.ChildNodes[2].Token.ValueString;
                            operation.WhereClauses.Add(column, val);
                        }
                    }
                }
                else if (node.Term.Name == "binExpr" && operation.WhereClauses.Count == 0)
                {
                    // Handle a single where clause.
                    var column = node.ChildNodes[0].ChildNodes[0].Token.ValueString;
                    var val = node.ChildNodes[2].Token.ValueString;
                    operation.WhereClauses.Add(column, val);
                }
            }
        }
开发者ID:kellabyte,项目名称:Dazzle.NET,代码行数:56,代码来源:SelectOperationBuilder.cs

示例10: Main

        static void Main ( string[] args )
        {
            Stack<int> stacker = new Stack<int>();
            stacker.Push(5);
            stacker.Push(4);
            Console.WriteLine(stacker.Contains(4));
            Console.WriteLine(stacker.Peek());
            Console.WriteLine(stacker.Pop());
            Console.WriteLine(stacker.Contains(4));
            Console.WriteLine(stacker.Peek());
            stacker.Clear();
            Console.WriteLine(stacker.IsEmpty());
            Console.WriteLine(stacker.Peek().GetType().Name);
            Console.ReadKey();

        }
开发者ID:Metatagross,项目名称:HackBulgaria-CSharp,代码行数:16,代码来源:Program.cs

示例11: Main

    static void Main()
    {
        Stack<int> myStack = new Stack<int>();
            myStack.Push(1);
            myStack.Push(2);
            myStack.Push(3);
            myStack.Push(4);
            myStack.Push(5);
            myStack.Push(6);

            int[] stackToArray = myStack.ToArray();
            Console.Write("{");
            for (int i = 0; i < stackToArray.Length-1; i++)
            {
                Console.Write(stackToArray[i] + ", ");
            }

            Console.Write(stackToArray[stackToArray.Length-1]+"}");
            Console.WriteLine();
            Console.WriteLine("the count="+myStack.Count);

            Console.WriteLine();
            Console.WriteLine(myStack.Peek());
            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Peek());
            Console.WriteLine(myStack.Pop());
            Console.WriteLine(myStack.Peek());
            Console.WriteLine("the count="+myStack.Count);

            Console.WriteLine(myStack.Contains(111));

            myStack.Clear();
            Console.WriteLine("the count="+myStack.Count);
    }
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:34,代码来源:ImplementStack.cs

示例12: CheckBracketsInExpression

 static bool CheckBracketsInExpression(string input)
 {
     Stack<char> stack = new Stack<char>();
     bool bracketsAreCorrect = true;
     for (int i = 0; i < input.Length; i++)
     {
         char currentChar = input[i];
         if (currentChar == '(')
         {
             stack.Push(currentChar);
         }
         else if (currentChar == ')')
         {
             if (!stack.Contains('('))
             {
                 bracketsAreCorrect = false;
                 break;
             }
             while (stack.Peek() != '(')
             {
                 stack.Pop();
             }
             stack.Pop();
         }
     }
     while (stack.Count > 0)
     {
         if (stack.Peek() == '(' || stack.Peek() == ')')
         {
             bracketsAreCorrect = false;
             break;
         }
     }
     return bracketsAreCorrect;
 }
开发者ID:tdochev,项目名称:TelerikAcademy,代码行数:35,代码来源:CheckBrackets.cs

示例13: FindNearestCommonParent

        private static int FindNearestCommonParent(int node1, int node2)
        {
            Stack<int> parentsToNode1 = new Stack<int>();
            Stack<int> parentsToNode2 = new Stack<int>();

            parentsToNode1.Push(node1);
            parentsToNode2.Push(node2);

            while (true)
            {
                if (parentsToNode2.Contains(parentsToNode1.Peek()))
                    return parentsToNode1.Peek();
                if (parentsToNode1.Contains(parentsToNode2.Peek()))
                    return parentsToNode2.Peek();
                if (node1 != treeRoot)
                {
                    node1 = parents[node1];
                    parentsToNode1.Push(node1);
                }
                if (node2 != treeRoot)
                {
                    node2 = parents[node2];
                    parentsToNode2.Push(node2);
                }
            }
        }
开发者ID:nadiahristova,项目名称:Data-Structures-Algorithms-and-Complexity,代码行数:26,代码来源:LongestPathInTree.cs

示例14: GenerateWater

 public void GenerateWater(List<VoronoiSite> sites)
 {
     NoiseGenerator.Frequency = 0.0005;
     foreach (VoronoiSite site in sites)
     {
         if ((site.IsOnBorder && RandomGenerator.GetDouble(0, 1) < 0.60) || (NoiseGenerator.Noise((int) site.VoronoiCenter[0], (int) site.VoronoiCenter[1]) + 1)*127 < 125)
             site.IsWater = true;
     }
     Stack<VoronoiSite> processingStack = new Stack<VoronoiSite>(sites.Where(s=>s.IsWater));
     while (processingStack.Count > 0)
     {
         VoronoiSite site = processingStack.Pop();
         if (!site.IsOnBorder && RandomGenerator.GetDouble(0, 1) < 0.50)
             continue;
         double threshold = site.IsOnBorder ? RandomGenerator.GetDouble(0, 0.85) : RandomGenerator.GetDouble(0, 0.67);
         foreach (VoronoiSite target in site.Neighbourgs)
         {
             if (target.IsWater)
                 continue;
             if (RandomGenerator.GetDouble(0, 1) < threshold)
             {
                 target.IsWater = true;
                 if (!processingStack.Contains(target))
                     processingStack.Push(target);
             }
         }
     }
     //Remove single cell islands
     foreach (VoronoiSite island in sites.Where(p => !p.IsWater && p.Neighbourgs.All(i => i.IsWater)))
         island.IsWater = true;
 }
开发者ID:ndech,项目名称:Alpha,代码行数:31,代码来源:PerlinWaterGenerator.cs

示例15: buildLadder

        /// <summary>
        /// Builds a linked list of transmissionUnits, over which the powerflow solver can sweep. 
        /// </summary>
        /// <param name="newLine"></param>
        private void buildLadder(Line newLine)
        {
            ladder = new LinkedList<TransmissionUnit>();
            var sourceUnit = new TransmissionUnit(newLine.ConnectivityNodes[newLine.bus1],newLine.BaseKV);
            var callStack = new Stack<TransmissionUnit>();
            var visited = new Stack<TopologicalNode.DynamicTopologicalNode>();
            callStack.Push(sourceUnit);
            TransmissionUnit currentUnit;
            TransmissionUnit newUnit;
            while (callStack.Count != 0)
            {
                currentUnit = callStack.Pop();
                ladder.AddLast(currentUnit);
                if (visited.Contains(currentUnit.Node))
                {
                    //Since the ladder powerflow only works for radial networks, as implemented.
                    throw new Exception("There was a loop in the feeder");
                }
                foreach (Terminal term in currentUnit.DownstreamTerms())
                {
                    newUnit = new TransmissionUnit(term, currentUnit);
                    callStack.Push(newUnit);
                }
                visited.Push(currentUnit.Node);
            }

        }
开发者ID:tonyju,项目名称:DSMviewer,代码行数:31,代码来源:LadderPowerFlow.cs


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