本文整理汇总了C#中LinkedStack.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedStack.Peek方法的具体用法?C# LinkedStack.Peek怎么用?C# LinkedStack.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedStack
的用法示例。
在下文中一共展示了LinkedStack.Peek方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPeakAfterPushPopElement
public void TestPeakAfterPushPopElement()
{
var stack = new LinkedStack<int>();
stack.Push(10);
stack.Push(20);
Assert.AreEqual(20, stack.Peek());
stack.Pop();
Assert.AreEqual(10, stack.Peek());
}
示例2: Test02StackPeek
public void Test02StackPeek()
{
var s = new LinkedStack<int>();
s.Push(3);
s.Push(1);
s.Push(8);
s.Push(5);
Assert.AreEqual(5, s.Peek());
s.Pop();
Assert.AreEqual(8, s.Peek());
s.Pop();
Assert.AreEqual(1, s.Peek());
}
示例3: PushingElementShouldContainElement
public void PushingElementShouldContainElement()
{
var stack = new LinkedStack<int>();
stack.Push(6);
Assert.IsTrue(stack.Peek() == 6, "The stack must contain 6.");
Assert.IsTrue(stack.Count == 1, "The stack count must be 1.");
}
示例4: Main
public static void Main(string[] args)
{
var stack = new LinkedStack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
stack.Push(4);
stack.Pop();
var array = stack.ToArray();
Console.WriteLine(stack.Peek());
}
示例5: PushPeekManyElementsShouldSetCountCorrectlyAndReturnCorrectElement
public void PushPeekManyElementsShouldSetCountCorrectlyAndReturnCorrectElement()
{
LinkedStack<string> stack = new LinkedStack<string>();
Assert.AreEqual(0, stack.Count, "Count for newly created stack is not correct.");
for (int i = 0; i < 1000; i++)
{
stack.Push(i.ToString());
}
for (int i = 1000; i >= 0; i--)
{
Assert.AreEqual("999", stack.Peek(), "Peeked element is not correct.");
Assert.AreEqual(1000, stack.Count, "Count after element peeking is not correct");
}
}
示例6: PeekOnEmptyStackShouldThrowException
public void PeekOnEmptyStackShouldThrowException()
{
LinkedStack<int> stack = new LinkedStack<int>();
stack.Peek();
}
示例7: PeekFromEmptyStackShotuldThrowException
public void PeekFromEmptyStackShotuldThrowException()
{
var stack = new LinkedStack<int>();
stack.Peek();
}