本文整理汇总了C#中Deque类的典型用法代码示例。如果您正苦于以下问题:C# Deque类的具体用法?C# Deque怎么用?C# Deque使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deque类属于命名空间,在下文中一共展示了Deque类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UndoBuffer
//--------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="UndoBuffer"/> class.
/// </summary>
public UndoBuffer()
{
InternalUndoStack = new Deque<IUndoableOperation>();
InternalRedoStack = new Deque<IUndoableOperation>();
UndoStack = new ReadOnlyCollection<IUndoableOperation>(InternalUndoStack);
RedoStack = new ReadOnlyCollection<IUndoableOperation>(InternalRedoStack);
}
示例2: TestRemoveAndTrim
public void TestRemoveAndTrim()
{
var d = new Deque<int>(4);
Assert.IsTrue(d.Count == 0);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(0);
d.AddLast(1);
d.AddLast(2);
d.AddLast(3);
d.AddLast(4);
d.AddLast(5);
Assert.IsTrue(d.Count == 6);
Assert.IsTrue(d.Capacity == 8);
d.RemoveLast();
d.RemoveLast();
d.RemoveLast();
Assert.IsTrue(d.Count == 3);
Assert.IsTrue(d.Capacity == 8);
d.TrimExcess();
Assert.IsTrue(d.Count == 3);
Assert.IsTrue(d.Capacity == 3);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}
示例3: ContainsPUT
public void ContainsPUT([PexAssumeUnderTest]IList<int> values, int val)
{
PexAssume.IsTrue(values.Contains(val));
Deque<int> actual = new Deque<int> (values);
Assert.AreEqual(true, actual.Contains(val));
}
示例4: Main
static void Main()
{
Deque<int> deque = new Deque<int>();
Deque<object> dequeOfObjects = new Deque<object>();
//dequeOfIntegers.AddFront(5);
//dequeOfIntegers.AddBack(10);
//int frontRemoved = dequeOfIntegers.RemoveFront();
//int backRemoced = dequeOfIntegers.RemoveBack();
//int frontPeek = dequeOfIntegers.PeekFront();
//int backPeek = dequeOfIntegers.PeekBack();
//int elements = dequeOfIntegers.Count;
//int maxCapacity = dequeOfIntegers.Capacity;
deque.AddFront(10);
deque.AddFront(50);
System.Console.WriteLine(deque.Count);
deque[0] = 500;
System.Console.WriteLine(deque[0]);
Deque<int> anotherDeque = new Deque<int>();
anotherDeque.AddFront(5);
anotherDeque.AddFront(10);
Deque<int> result = deque + anotherDeque;
}
示例5: 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
}
示例6: TestAddAndGrow
public void TestAddAndGrow()
{
var d = new Deque<int>(0);
Assert.IsTrue(d.Count == 0);
Assert.IsTrue(d.Capacity == 0);
d.AddFirst(1);
Assert.IsTrue(d.Count == 1);
Assert.IsTrue(d.Capacity == 4);
d.AddFirst(0);
Assert.IsTrue(d.Count == 2);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(2);
d.AddLast(3);
Assert.IsTrue(d.Count == 4);
Assert.IsTrue(d.Capacity == 4);
d.AddLast(4);
Assert.IsTrue(d.Count == 5);
Assert.IsTrue(d.Capacity == 8);
var arr = d.ToArray();
var exp = new int[] { 0, 1, 2, 3, 4 };
Assert.IsTrue(arr.Length == exp.Length);
for (int i = 0; i < arr.Length; i++) {
Assert.IsTrue(arr[i] == exp[i]);
}
}
示例7: ClearPUT
public void ClearPUT([PexAssumeUnderTest]int[] input)
{
Deque<int> actual = new Deque<int> (input);
actual.Clear();
PexAssert.AreEqual(0, actual.Count);
}
示例8: Should_return_isEmpty_after_ctor
public void Should_return_isEmpty_after_ctor()
{
// arrange
var deque = new Deque<string>();
// act
// assert
Assert.IsTrue(deque.IsEmpty());
}
示例9: CopyConstructorPUT
public void CopyConstructorPUT(int[] input)
{
Deque<int> actual = new Deque<int>(input);
int[] output = new int[input.Length];
actual.CopyTo(output, 0);
CollectionAssert.AreEqual(input, output);
}
示例10: CopyConstructorTest
public void CopyConstructorTest()
{
List<int> original = new List<int> { 12, 123, 1, 90 };
Deque<int> actual = new Deque<int>(original);
Deque<int> expected = new Deque<int> { 12, 123, 1, 90 };
CollectionAssert.AreEqual(expected, actual);
}
示例11: ConstructorExample
public void ConstructorExample()
{
var deque = new Deque<string>();
deque.EnqueueHead("cat");
deque.EnqueueHead("dog");
deque.EnqueueHead("canary");
Assert.AreEqual(3, deque.Count);
}
示例12: ClearTest
public void ClearTest()
{
Deque<int> actual = new Deque<int> { 12, 45, 321 };
actual.Clear();
Assert.AreEqual(0, actual.Count);
}
示例13: Simple
public void Simple()
{
var deque = new Deque<int>();
Assert.IsFalse(deque.IsReadOnly);
deque = GetTestDeque();
Assert.IsFalse(deque.IsReadOnly);
}
示例14: DequeueBackCountNonEmptyDequeTest
public void DequeueBackCountNonEmptyDequeTest()
{
Deque<int> actual = new Deque<int> { 10, 12, 13 };
actual.DequeueBack();
Assert.AreEqual(2, actual.Count);
}
示例15: SetUp
public void SetUp()
{
d = new Deque<int>();
q = new Queue<int>();
s = new Stack<int>();
l = new List<int>();
ll = new LinkedList<int>();
}