本文整理汇总了C#中SinglyLinkedLists.SinglyLinkedList.AddFirst方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.AddFirst方法的具体用法?C# SinglyLinkedList.AddFirst怎么用?C# SinglyLinkedList.AddFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedLists.SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.AddFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFirstOnEmptyList
public void AddFirstOnEmptyList()
{
SinglyLinkedList list = new SinglyLinkedList();
list.AddFirst("foo");
string[] expected = new string[] { "foo" };
CollectionAssert.AreEqual(expected, list.ToArray());
}
示例2: AddFirstOnLongerList
public void AddFirstOnLongerList()
{
SinglyLinkedList list = new SinglyLinkedList();
list.AddLast("foo");
list.AddLast("bar");
list.AddFirst("grille");
var expected = new string[] { "grille", "foo", "bar" };
CollectionAssert.AreEqual(expected, list.ToArray());
}
示例3: AddFirst
public void AddFirst(string value)
{
//if this is the first node, this is just an assignment
if (this.First() == null)
{
first_node = new SinglyLinkedListNode(value);
}
else
{
//create a placeholder list to store the values in order.
var placeholderList = new SinglyLinkedList();
placeholderList.AddFirst(value);
for (var i = 0; i < this.Count(); i++)
{
placeholderList.AddLast(this.ElementAt(i));
}
//now reassign the values to the current linked list in order (this.First() etc)
first_node = new SinglyLinkedListNode(placeholderList.First());
for (var q = 1; q < placeholderList.Count(); q++ )
{
this.AddLast(placeholderList.ElementAt(q));
}
}
}
示例4: testIndexOfNodeInFirst
public void testIndexOfNodeInFirst()
{
SinglyLinkedList list = new SinglyLinkedList();
list.AddFirst("node1");
Assert.AreEqual(0, list.IndexOf("node1"));
}
示例5: testIndexOfNodeForMultipleItems
public void testIndexOfNodeForMultipleItems()
{
SinglyLinkedList list = new SinglyLinkedList();
list.AddFirst("node1");
list.AddLast("node2");
Assert.AreEqual(1, list.IndexOf("node2"));
}
示例6: AddFirst
public void AddFirst(string value)
{
if (this.First() == null)
{
first_node = new SinglyLinkedListNode(value);
}
else
{
var newFirstNode = new SinglyLinkedListNode(value);
var placeHolderList = new SinglyLinkedList();
placeHolderList.AddFirst(newFirstNode.Value);
for (var i = 0; i < this.Count(); i++)
{
placeHolderList.AddLast(this.ElementAt(i));
}
first_node = new SinglyLinkedListNode(placeHolderList.First());
for (var q = 1; q < placeHolderList.Count(); q++)
{
this.AddLast(placeHolderList.ElementAt(q));
}
}
}