本文整理汇总了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;
}
示例2: StackPushOne
public void StackPushOne()
{
Stack<int> s = new Stack<int>();
s.Push(10);
int n = s.Size();
Assert.AreEqual(1, n);
}
示例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();
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例8: Size_Zero_Test
public void Size_Zero_Test()
{
var stack = new Stack<int>();
Assert.AreEqual(0, stack.Size());
}
示例9: StackPopEmpty
public void StackPopEmpty()
{
Stack<int> s = new Stack<int>();
s.Pop();
Assert.AreEqual(0, s.Size());
}
示例10: StackSizeWhenEmpty
public void StackSizeWhenEmpty()
{
Stack<int> s = new Stack<int>();
int n = s.Size();
Assert.AreEqual(0, n);
}