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