本文整理汇总了C#中Deque.PeekLast方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.PeekLast方法的具体用法?C# Deque.PeekLast怎么用?C# Deque.PeekLast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deque
的用法示例。
在下文中一共展示了Deque.PeekLast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
internal static void Main()
{
Deque<int> deque = new Deque<int>();
deque.PushFirst(3);
deque.PushFirst(5);
deque.PushFirst(7);
deque.PushLast(10);
deque.PushLast(13);
//The order of elements in Deque is: 7, 5, 3, 10, 13
//This will write on console first element without removing it from Deque -> 7
Console.WriteLine("Peek first element: {0}", deque.PeekFirst());
//This will write on console last element without removing it from Deque -> 13
Console.WriteLine("Peek last element: {0}", deque.PeekLast());
//This will write on console first element and remove it from Deque -> 7 again
Console.WriteLine("Pop first element: {0}", deque.PopFirst());
//This will write on console first element and remove it from Deque -> 5 again
Console.WriteLine("Pop first element: {0}", deque.PopFirst());
//This will write on console last element and remove it from Deque -> 13 again
Console.WriteLine("Pop last element: {0}", deque.PopLast());
//In the deque now you have only two elements -> 3 and 10
}
示例2: TestValuesAndWrapAround
public void TestValuesAndWrapAround()
{
var d = new Deque<int>(4);
d.AddLast(1); // internally it contains [H:1, 2, 3, 4]
d.AddLast(2);
d.AddLast(3);
d.AddLast(4);
Assert.IsTrue(d.PeekFirst() == 1 & d.PeekLast() == 4);
d.RemoveFirst();
d.RemoveLast(); // now it's [0, H:2, 3, 0]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 3);
d.AddLast(4);
d.RemoveFirst(); // now it's [0, 0, H:3, 4]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 3 & d.PeekLast() == 4);
d.AddLast(5);
d.RemoveFirst(); // now it's [5, 0, 0, H:4]
Assert.IsTrue(d.Count == 2 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 4 & d.PeekLast() == 5);
d.AddFirst(3);
d.AddFirst(2); // now it's [5, H:2, 3, 4]
Assert.IsTrue(d.Count == 4 && d.Capacity == 4);
Assert.IsTrue(d.PeekFirst() == 2 & d.PeekLast() == 5);
d.AddFirst(1); // reallocated to [H:1, 2, 3, 4, 5, 0, 0, 0]
d.AddFirst(0); // now it's [1, 2, 3, 4, 5, 0, 0, H:0]
Assert.IsTrue(d.Count == 6 && d.Capacity == 8);
Assert.IsTrue(d.PeekFirst() == 0 & d.PeekLast() == 5);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2, 3, 4, 5 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}