本文整理汇总了C#中SinglyLinkedList.AddFirst方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.AddFirst方法的具体用法?C# SinglyLinkedList.AddFirst怎么用?C# SinglyLinkedList.AddFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.AddFirst方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFirst_Should_change_tail_when_tail_is_null
public void AddFirst_Should_change_tail_when_tail_is_null()
{
ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new int[0]);
list = list.AddFirst(1);
Assert.That(list.Head.Data, Is.EqualTo(1));
Assert.That(list.Tail.Data, Is.EqualTo(1));
}
示例2: Adding_Should_increment_length
public void Adding_Should_increment_length()
{
ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new[] { 1 });
Assert.That(list.Length, Is.EqualTo(1));
list = list.AddAfter(2,list.Tail);
Assert.That(list.Length, Is.EqualTo(2));
list = list.AddFirst(3);
Assert.That(list.Length, Is.EqualTo(3));
list = list.AddLast(4);
Assert.That(list.Length, Is.EqualTo(4));
}
示例3: TestRemoveFirst
public void TestRemoveFirst()
{
var expected = new int[2] { 0, 1 };
var list = new SinglyLinkedList<int>(expected);
list.AddFirst(-1);
Assert.AreEqual(-1, list.First.Value);
list.RemoveFirst();
Verify(expected, list);
}
示例4: TestAddFirst
public void TestAddFirst()
{
var expected = new int[2] { 0, 1 };
var list = new SinglyLinkedList<int>();
list.AddFirst(1);
list.AddFirst(0);
Verify(expected, list);
}
示例5: RemoveFirstTest
public void RemoveFirstTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int>();
sll.AddFirst(40);
sll.AddFirst(30);
sll.AddFirst(20);
sll.AddFirst(10);
sll.AddLast(50);
sll.RemoveFirst();
sll.RemoveFirst();
Assert.AreEqual(30, sll.Head.Value);
Assert.AreEqual(50, sll.Tail.Value);
Assert.AreEqual(3, sll.Count);
}
示例6: AddFirstTest
public void AddFirstTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int>();
sll.AddFirst(10);
sll.AddFirst(20);
sll.AddFirst(30);
Assert.AreEqual(30, sll.Head.Value);
Assert.AreEqual(20, sll.Head.Next.Value);
Assert.AreEqual(10, sll.Tail.Value);
}
示例7: AddFirst_Should_change_head
public void AddFirst_Should_change_head()
{
ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new[] { 1 });
list = list.AddFirst(2);
Assert.That(list.Head.Data, Is.EqualTo(2));
}