本文整理汇总了C#中ArrayStack.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayStack.Peek方法的具体用法?C# ArrayStack.Peek怎么用?C# ArrayStack.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayStack
的用法示例。
在下文中一共展示了ArrayStack.Peek方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPeakAfterPushPopElement
public void TestPeakAfterPushPopElement()
{
var stack = new ArrayStack<int>();
stack.Push(10);
stack.Push(20);
Assert.AreEqual(20, stack.Peek());
stack.Pop();
Assert.AreEqual(10, stack.Peek());
}
示例2: Pop_deleteCellReturned
public void Pop_deleteCellReturned()
{
ArrayStack<int> st = new ArrayStack<int>();
st.Stack(5);
st.Push(1);
st.Push(2);
Console.WriteLine("Количество элементов в стеке: " + st.GetCount);
Console.WriteLine("Верхний элемент стека: " + st.Peek());
st.Pop();
Console.WriteLine("Удален верхний элемент стека \n\n");
Console.WriteLine("Количество элементов в стеке: " + st.GetCount);
Console.WriteLine("Верхний элемент стека: " + st.Peek());
}
示例3: PushingElementShouldContainElement
public void PushingElementShouldContainElement()
{
var stack = new ArrayStack<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 ArrayStack<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()
{
ArrayStack<string> stack = new ArrayStack<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: Main
// Implement the ADT stack as auto-resizable array.
// Resize the capacity on demand (when no space is available to add / insert a new element).
public static void Main()
{
var stack = new ArrayStack<int>();
stack.Push(1);
stack.Push(2);
stack.Push(3);
stack.Push(4);
Console.WriteLine("Stack: {0}", stack);
stack.Push(5);
Console.WriteLine("Push 5...");
Console.WriteLine("Stack: {0}", stack);
Console.WriteLine("Peek: {0}", stack.Peek());
Console.WriteLine("Pop: {0}", stack.Pop());
Console.WriteLine("Stack: {0}", stack);
Console.WriteLine("Pop: {0}", stack.Pop());
Console.WriteLine("Stack: {0}", stack);
}
示例7: Main
static void Main()
{
ArrayStack stack = new ArrayStack(5);
stack.Push(4);
stack.Push("This is cool");
stack.Push(new Node("NodeString"));
stack.Push(5.356);
stack.Push('d');
Console.WriteLine("Stack full? "+stack.IsFull());
for (int i=0; i<stack.Count; i++)
{
Console.WriteLine(stack[i]);
}
stack.Pop();
stack.Pop();
stack.Pop();
stack.Pop();
Console.WriteLine(stack.Peek());
stack.Pop();
Console.WriteLine(stack.IsEmpty());
}
示例8: Main
static void Main()
{
var stack = new ArrayStack<int>();
int[] arr1 = stack.ToArray();
Console.WriteLine(string.Join(", ", arr1));
stack.Push(1);
stack.Push(2);
stack.Push(3);
stack.Push(4);
stack.Push(5);
stack.Push(6);
stack.Push(7);
//Console.WriteLine(stack.Pop());
//stack.Pop();
//stack.Pop();
//stack.Pop();
//stack.Pop();
//stack.Pop();
//Console.WriteLine(stack.Contains(50));
Console.WriteLine(stack.Peek());
Console.WriteLine(stack.Count);
int[] arr = stack.ToArray();
Console.WriteLine(string.Join(", ", arr));
var stack1 = new ArrayStack<int>();
//stack1.Pop();
var st = new Stack<int>();
//st.Push(1);
//st.Push(2);
//st.Push(3);
//Console.WriteLine(string.Join(", ", st.ToArray()));
}
示例9: PushElementFromStackWithCapacity1ShouldContainElement
public void PushElementFromStackWithCapacity1ShouldContainElement()
{
var stack = new ArrayStack<int>(1);
stack.Push(6);
Assert.IsTrue(stack.Peek() == 6, "The stack must contain 6.");
Assert.IsTrue(stack.Count == 1, "The stack count must be 1.");
}
示例10: PeekFromEmptyStackShotuldThrowException
public void PeekFromEmptyStackShotuldThrowException()
{
var stack = new ArrayStack<int>();
stack.Peek();
}
示例11: PeekOnEmptyStackShouldThrowException
public void PeekOnEmptyStackShouldThrowException()
{
ArrayStack<int> stack = new ArrayStack<int>(4);
stack.Peek();
}