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


C# Stack.Size方法代码示例

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


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

示例1: VerifyExpression

        static int VerifyExpression(string s)
        {
            Stack<char> stack = new Stack<char>();

            int err = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '*')
                {
                    if (stack.Size() == 1 || stack.Size() == 0)
                    {
                        err += 1;
                    }
                    else
                    {
                        stack.Pop();
                    }
                }
                else
                {
                    stack.Push(s[i]);
                }
            }

            if (stack.Size() == 1)
                return err;
            else
                return err + stack.Size() / 2;
        }
开发者ID:yizhengc,项目名称:MyAlgorithmCode,代码行数:30,代码来源:Expression.cs

示例2: StackPushOne

 public void StackPushOne()
 {
     Stack<int> s = new Stack<int>();
     s.Push(10);
     int n = s.Size();
     Assert.AreEqual(1, n);
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:7,代码来源:StackUnitTests.cs

示例3: Run

        public void Run()
        {
            const string fieName = "tobe.txt";

            var @in = new In($"Files\\Collections\\{fieName}");
            var words = @in.ReadAllStrings();

            var stack = new Stack<string>();

            foreach (var word in words)
            {
                stack.Push(word);
            }
            Console.WriteLine("size of stack = {0}", stack.Size());
            foreach (var item in stack)
            {
                Console.WriteLine("item = {0}", item);
            }
            while (!stack.IsEmpty())
            {
                var item = stack.Pop();
                Console.WriteLine("item = {0}", item);
            }
            Console.ReadLine();
        }
开发者ID:vladdnc,项目名称:Algorithms-NET,代码行数:25,代码来源:StackWorker.cs

示例4: Push_First_Null_Test

        public void Push_First_Null_Test()
        {
            var stack = new Stack<int>();
            stack.Push(9);

            Assert.AreEqual(1, stack.Size());
            Assert.AreEqual(9, stack.Peek());
        }
开发者ID:hong-rong,项目名称:MyRepository,代码行数:8,代码来源:StackTests.cs

示例5: StackPopOne

 public void StackPopOne()
 {
     Stack<int> s = new Stack<int>();
     s.Push(20);
     int n = s.Pop();
     Assert.AreEqual(0, s.Size());
     Assert.AreEqual(20, n);
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:8,代码来源:StackUnitTests.cs

示例6: StackPushMultiple

 public void StackPushMultiple()
 {
     Stack<int> s = new Stack<int>();
     for(int i=0; i<10; i++)
     {
         s.Push(i);
     }
     int n = s.Size();
     Assert.AreEqual(10, n);
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:10,代码来源:StackUnitTests.cs

示例7: StackPopMultiple

 public void StackPopMultiple()
 {
     Stack<int> s = new Stack<int>();
     for(int i=0; i<10; i++)
     {
         s.Push(i);
     }
     int n1 = s.Pop();
     int n2 = s.Pop();
     Assert.AreEqual(8, s.Size());
     Assert.AreEqual(n1, 9);
     Assert.AreEqual(n2, 8);
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:13,代码来源:StackUnitTests.cs

示例8: Size_Zero_Test

        public void Size_Zero_Test()
        {
            var stack = new Stack<int>();

            Assert.AreEqual(0, stack.Size());
        }
开发者ID:hong-rong,项目名称:MyRepository,代码行数:6,代码来源:StackTests.cs

示例9: StackPopEmpty

 public void StackPopEmpty()
 {
     Stack<int> s = new Stack<int>();
     s.Pop();
     Assert.AreEqual(0, s.Size());
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:6,代码来源:StackUnitTests.cs

示例10: StackSizeWhenEmpty

 public void StackSizeWhenEmpty()
 {
     Stack<int> s = new Stack<int>();
     int n = s.Size();
     Assert.AreEqual(0, n);
 }
开发者ID:matteougolotti,项目名称:Experiments,代码行数:6,代码来源:StackUnitTests.cs


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