本文整理汇总了C#中SinglyLinkedList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.Add方法的具体用法?C# SinglyLinkedList.Add怎么用?C# SinglyLinkedList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginTestMethod
public void BeginTestMethod()
{
target = new SinglyLinkedList<int>();
Assert.AreEqual(target.Leng, 0);
target.Add(2);
target.Add(3, 1);
target.AddLast(5);
}
示例2: TestSinglyLinkedListAdd
public void TestSinglyLinkedListAdd()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
Assert.AreEqual(3, list.Count);
}
示例3: LastIndexOf_ExistingItem_ShouldReturnCorrectIndex
public void LastIndexOf_ExistingItem_ShouldReturnCorrectIndex()
{
var list = new SinglyLinkedList<int>();
list.Add(1);
list.Add(101);
list.Add(1);
list.Add(101);
var index = list.LastIndexOf(1);
Assert.AreEqual(2, index);
}
示例4: TestSinglyLinkedListIndexer
public void TestSinglyLinkedListIndexer()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
list[0] = "Zero";
string[] array = new string[list.Count];
list.CopyTo(array);
Assert.AreEqual("Zero, Two, Three", string.Join(", ", array));
}
示例5: FirstIndexOf_NonExistingItem_ShouldReturnMinusOne
public void FirstIndexOf_NonExistingItem_ShouldReturnMinusOne()
{
var list = new SinglyLinkedList<int>();
list.Add(1);
list.Add(101);
list.Add(1);
list.Add(101);
var index = list.FirstIndexOf(1001);
Assert.AreEqual(-1, index);
}
示例6: TestSinglyLinkedListInsert_InsertInTheMiddle
public void TestSinglyLinkedListInsert_InsertInTheMiddle()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
list[0] = "Zero";
list.Insert(1, "Ten");
string[] array = new string[list.Count];
list.CopyTo(array);
Assert.AreEqual("Zero, Ten, Two, Three", string.Join(", ", array));
}
示例7: TestSinglyLinkedList
public void TestSinglyLinkedList()
{
SinglyLinkedList<int> singlyLinkedList = new SinglyLinkedList<int>();
singlyLinkedList.AddAtEnd(5);
singlyLinkedList.AddAtEnd(6);
singlyLinkedList.AddAtEnd(7);
singlyLinkedList.AddAtEnd(8);
singlyLinkedList.AddAtStart(4);
singlyLinkedList.AddAtStart(3);
singlyLinkedList.AddAtStart(2);
singlyLinkedList.AddAtStart(1);
singlyLinkedList.Add(9, 10);
singlyLinkedList.Add(11, 9, true);
singlyLinkedList.Add(10, 11);
}
示例8: Main
static void Main()
{
var myList = new SinglyLinkedList<int>();
myList.Add(1);
myList.Add(2);
myList.Add(3);
myList.Add(2);
myList.Add(1);
Console.WriteLine(string.Join(" ", myList));
Console.WriteLine(myList.FirstIndexOf(2));
myList.Remove(4);
Console.WriteLine(string.Join(" ", myList));
Console.WriteLine(myList.Count);
}
示例9: 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 + " ");
}
}
示例10: 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");
}
示例11: TestSinglyLinkedListForEach
public void TestSinglyLinkedListForEach()
{
SinglyLinkedList<string> list = new SinglyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
list[0] = "Zero";
string[] array = new string[list.Count];
int index = 0;
foreach (string item in list)
{
array[index] = item;
index++;
}
Assert.AreEqual("Zero, Two, Three", string.Join(", ", array));
}
示例12: SortListTest
public void SortListTest()
{
var list = new SinglyLinkedList<int>();
foreach (int n in a) {
list.Add(n);
}
MergeSort.Sort(list);
string expected = "[ -59 -45 -12 11 11 44 53 62 80 94 ]";
string actual = list.ToString();
Assert.AreEqual(actual, expected);
}
示例13: Add_EmptyList_ShouldIncrementCount
public void Add_EmptyList_ShouldIncrementCount()
{
const int N = 100;
var list = new SinglyLinkedList<int>();
for (int i = 0; i < N; i++)
{
list.Add(i);
}
Assert.AreEqual(N, list.Count);
}
示例14: 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));
}
示例15: Add_EmptyList_ShouldAdd
public void Add_EmptyList_ShouldAdd()
{
const int N = 100;
var list = new SinglyLinkedList<int>();
for (int i = 0; i < N; i++)
{
list.Add(i);
}
int currentItem = 0;
foreach (var item in list)
{
Assert.AreEqual(currentItem, item);
currentItem++;
}
}