本文整理汇总了C#中SinglyLinkedList.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList.Remove方法的具体用法?C# SinglyLinkedList.Remove怎么用?C# SinglyLinkedList.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SinglyLinkedList
的用法示例。
在下文中一共展示了SinglyLinkedList.Remove方法的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
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));
}
示例3: 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);
}
}
示例4: 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);
}
示例5: RemoveItemFromEmptySinglyLinkedListCollection
public void RemoveItemFromEmptySinglyLinkedListCollection()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int>();
Assert.IsFalse(sll.Remove(10));
}
示例6: Does_not_remove_node_when_matching_value_not_in_list
public void Does_not_remove_node_when_matching_value_not_in_list()
{
var head = new ListNode<int>(12) { Next = new ListNode<int>(42) { Next = new ListNode<int>(77) } };
var list = new SinglyLinkedList<int>(head);
list.Remove(new ListNode<int>(99));
Assert.That(list.Length, Is.EqualTo(3));
Assert.Null(list.Find(99));
}
示例7: RemoveTest
public void RemoveTest()
{
var list = new SinglyLinkedList<int> { 1, 0, -1, 1 };
Assert.IsTrue(list.Remove(1));
Assert.AreEqual(3, list.Count, "Did not remove the item");
}
示例8: Remove_value_from_single_item_list
public void Remove_value_from_single_item_list()
{
var list = new SinglyLinkedList<int>(new ListNode<int>(12));
list.Remove(12);
Assert.That(list.Length, Is.EqualTo(0));
Assert.Null(list.Head);
}
示例9: RemoveWithNoMatchTest
public void RemoveWithNoMatchTest()
{
SinglyLinkedList<int> sll = new SinglyLinkedList<int> {20, 30, 50};
Assert.AreEqual(3, sll.Count);
Assert.IsFalse(sll.Remove(110));
}
示例10: TestRemoveValue
public void TestRemoveValue()
{
var list = new SinglyLinkedList<string>();
list.AddLast("Expected");
list.AddLast("Expected");
list.AddLast("Not expected");
list.AddLast("Expected");
Assert.IsTrue(list.Remove("Not expected"));
Assert.IsFalse(list.Contains("Not expected"));
}
示例11: Remove_ValidIndex_ShouldRemove
public void Remove_ValidIndex_ShouldRemove()
{
const int N = 100;
var list = new SinglyLinkedList<int>();
for (int i = 0; i < N; i++)
{
list.Add(i);
list.Remove(0);
}
Assert.AreEqual(0, list.Count);
}
示例12: RemoveOnlyNodeInListTest
public void RemoveOnlyNodeInListTest()
{
SinglyLinkedList<int> actual = new SinglyLinkedList<int> { 12 };
actual.Remove(12);
Assert.IsNull(actual.Head);
Assert.IsNull(actual.Tail);
}
示例13: Remove_ValidIndex_ShouldDecrementCount
public void Remove_ValidIndex_ShouldDecrementCount()
{
const int N = 100;
var list = new SinglyLinkedList<int>();
for (int i = 0; i < N; i++)
{
list.Add(i);
}
list.Remove(0);
list.Remove(1);
list.Remove(2);
Assert.AreEqual(N - 3, list.Count);
}
示例14: Remove_InvalidIndex_ShouldThrow
public void Remove_InvalidIndex_ShouldThrow()
{
var list = new SinglyLinkedList<int>();
list.Remove(0);
}
示例15: RemoveWithNoMatchTest
public void RemoveWithNoMatchTest([PexAssumeUnderTest]List<string> list, string inputval)
{
PexAssume.IsFalse(list.Contains(inputval));
SinglyLinkedList<string> sll = new SinglyLinkedList<string> (list);
PexAssert.AreEqual(list.Count, sll.Count);
PexAssert.IsFalse(sll.Remove(inputval));
}