本文整理汇总了C#中SinglyLinkedList类的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList类的具体用法?C# SinglyLinkedList怎么用?C# SinglyLinkedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SinglyLinkedList类属于命名空间,在下文中一共展示了SinglyLinkedList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var list = new SinglyLinkedList<int>();
for (int i = 0; i < 10; i++)
{
list.Add(i);
Console.Write("Added " + i);
Console.WriteLine(" Count -> " + list.Count);
}
Console.WriteLine("Items:");
foreach (var item in list)
{
Console.Write(item + " ");
}
Console.WriteLine();
int index = 0;
for (int i = 0; i < 10; i++)
{
list.Remove(i - index++);
Console.Write("Remmoved " + i);
Console.WriteLine(" Count -> " + list.Count);
}
Console.WriteLine("Items:");
foreach (var item in list)
{
Console.Write(item + " ");
}
}
示例2: Main
static void Main()
{
SinglyLinkedList<int> list = new SinglyLinkedList<int>();
list.AddLast(1);
list.AddLast(2);
list.AddLast(3);
list.AddLast(4);
list.AddLast(5);
list.AddLast(6);
list.AddLast(3);
Console.WriteLine("FirstIndexOf(6): {0}", list.FirstIndexOf(6));
Console.WriteLine("FirstIndexOf(1): {0}", list.FirstIndexOf(1));
Console.WriteLine("FirstIndexOf(16): {0}", list.FirstIndexOf(16));
Console.WriteLine("LastIndexOf(3): {0}", list.LastIndexOf(3));
Console.WriteLine("LastIndexOf(30): {0}", list.LastIndexOf(30));
Console.WriteLine(list.Count);
list.Remove(0);
foreach (var item in list)
{
Console.WriteLine(item);
}
}
示例3: 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));
}
示例4: AddTest
public void AddTest()
{
var list = new SinglyLinkedList<int> { 1, 0, -1 };
Assert.AreEqual(3, list.Count, "Did not add the items");
list.Add(1);
Assert.AreEqual(4, list.Count, "Did not add the item");
}
示例5: Main
private static void Main()
{
var list = new SinglyLinkedList<int>();
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
list.Add(5);
list.Add(3);
list.Add(2);
list.Add(10, 1);
list.Add(5);
list.Add(99);
Console.WriteLine("Count = {0}", list.Count);
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
list.Remove(1);
Console.WriteLine("Count = {0}", list.Count);
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
Console.WriteLine(list.FirstIndexOf(5));
Console.WriteLine("--------------------");
Console.WriteLine(list.LastIndexOf(5));
}
示例6: BeginTestMethod
public void BeginTestMethod()
{
target = new SinglyLinkedList<int>();
Assert.AreEqual(target.Leng, 0);
target.Add(2);
target.Add(3, 1);
target.AddLast(5);
}
示例7: SinglyLinkedListIntIsNull
public void SinglyLinkedListIntIsNull()
{
_singlyLinkedListInt = null;
_index = 5;
int expected = 0;
var actual = _linkedListOperationsInt.GetNthElementFromLast(_singlyLinkedListInt, _index);
Assert.AreEqual(expected, actual);
}
示例8: SetupUnitTests
public void SetupUnitTests()
{
_linkedListOperationsInt = new LinkedListOperations<int>();
_singlyLinkedListInt = new SinglyLinkedList<int>();
_linkedListOperationsString = new LinkedListOperations<string>();
_singlyLinkedListString = new SinglyLinkedList<string>();
}
示例9: Create
public static SinglyLinkedList<int> Create(
SinglyLinkedListNode<int> node_singlyLinkedListNode,
int[] elements
)
{
PexAssume.IsNotNull(elements);
SinglyLinkedList<int> singlyLinkedList = new SinglyLinkedList<int>(elements);
return singlyLinkedList;
}
示例10: Append_value_to_end_of_single_item_list
public void Append_value_to_end_of_single_item_list()
{
var list = new SinglyLinkedList<int>(new ListNode<int>(12));
list.Append(42);
Assert.That(list.Length, Is.EqualTo(2));
Assert.That(list.Head.Next.Value, Is.EqualTo(42));
}
示例11: TestSinglyLinkedListAdd
public void TestSinglyLinkedListAdd()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
Assert.AreEqual(3, list.Count);
}
示例12: AddLast_Should_change_tail_and_set_next_of_previous_tail
public void AddLast_Should_change_tail_and_set_next_of_previous_tail()
{
ISinglyLinkedList<int> list = new SinglyLinkedList<int>(new[] { 1 });
var previous = list.Tail;
list = list.AddLast(2);
Assert.That(list.Tail.Data, Is.EqualTo(2));
Assert.That(previous.Next, Is.EqualTo(list.Tail));
}
示例13: CopyToTest
public void CopyToTest()
{
// NOTE: the Add method, adds them to the front of the list, therefore the list is in reverse
var list = new SinglyLinkedList<int> { 1, 0, -1 };
var expected = new int[] { -1, 0, 1 };
var actual = new int[list.Count];
list.CopyTo(actual, 0);
CollectionAssert.AreEqual(expected, actual, "The arrays do not match");
}
示例14: Append_single_node_to_empty_list
public void Append_single_node_to_empty_list()
{
var list = new SinglyLinkedList<int>(null);
var node = new ListNode<int>(42);
list.Append(node);
Assert.That(list.Length, Is.EqualTo(1));
Assert.That(list.Head, Is.EqualTo(node));
}
示例15: GetEnumeratorTest
public void GetEnumeratorTest()
{
// NOTE: the Add method, adds them to the front of the list, therefore the list is in reverse
var list = new SinglyLinkedList<int> { 1, 0, -1, 44, 22, 22, 11, 2, 3, 4, 5 };
var expected = new int[] { 5, 4, 3, 2, 11, 22, 22, 44, -1, 0, 1 };
var actual = new System.Collections.Generic.List<int>();
foreach (var item in list) { actual.Add(item); }
CollectionAssert.AreEqual(expected, actual, "The collections do not match");
}