本文整理汇总了C#中DoublyLinkedList类的典型用法代码示例。如果您正苦于以下问题:C# DoublyLinkedList类的具体用法?C# DoublyLinkedList怎么用?C# DoublyLinkedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoublyLinkedList类属于命名空间,在下文中一共展示了DoublyLinkedList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertionSort
private static void InsertionSort(DoublyLinkedList<double> bucket)
{
if (bucket.Head == null)
{
return;
}
var currentNode = bucket.Head.Next;
while (currentNode != null)
{
var node = currentNode.Previous;
while (node != null && node.Value > currentNode.Value)
{
node = node.Previous;
}
bucket.Delete(currentNode);
if (node != null)
{
bucket.InsertAfter(node, currentNode.Value);
}
else
{
bucket.Insert(currentNode.Value);
}
currentNode = currentNode.Next;
}
}
示例2: should_make_the_node_head_and_tail_of_the_list
public void should_make_the_node_head_and_tail_of_the_list()
{
var list = new DoublyLinkedList<int>();
list.Add(3);
Assert.That(list.Head.Data.Equals(3), Is.True);
Assert.That(list.Tail.Data.Equals(3), Is.True);
}
示例3: Sort
public static void Sort(double[] array)
{
var buckets = new DoublyLinkedList<double>[10];
for (var i = 0; i < buckets.Length; i++)
{
buckets[i] = new DoublyLinkedList<double>();
}
foreach (var v in array)
{
if (v < 0 || v >= 1)
{
throw new InvalidOperationException($"{v} is not in [0..1) range.");
}
buckets[(int)(v * 10)].Insert(v);
}
foreach (var bucket in buckets)
{
InsertionSort(bucket);
}
var index = 0;
foreach (var bucket in buckets)
{
for (var node = bucket.Head; node != null; node = node.Next)
{
array[index++] = node.Value;
}
}
}
示例4: Main
public static void Main()
{
var list = new DoublyLinkedList<int>();
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
list.AddLast(5);
list.AddFirst(3);
list.AddFirst(2);
list.AddLast(10);
Console.WriteLine("Count = {0}", list.Count);
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
list.RemoveFirst();
list.RemoveLast();
list.RemoveFirst();
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
list.RemoveLast();
list.ForEach(Console.WriteLine);
Console.WriteLine("--------------------");
}
示例5: should_return_the_node_if_the_value_exists
public void should_return_the_node_if_the_value_exists()
{
var list = new DoublyLinkedList<int>();
list.Add(5);
list.Add(3);
var node = list.Find(5);
Assert.That(node.Data.Equals(5), Is.True);
}
示例6: BeginTestMethod
public void BeginTestMethod()
{
target = new DoublyLinkedList<int>();
Assert.AreEqual(target.Leng, 0);
target.Add(2);
target.Add(3, 1);
target.AddLast(5);
}
示例7: TestDoublyLinkedListAdd
public void TestDoublyLinkedListAdd()
{
DoublyLinkedList<string> list = new DoublyLinkedList<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
Assert.AreEqual(3, list.Count);
}
示例8: AddAfterTailPUT
public void AddAfterTailPUT([PexAssumeUnderTest]IList<int> values, int toAddValue)
{
PexAssume.IsTrue(values.Count > 1);
PexAssume.IsFalse(values.Contains(toAddValue));
DoublyLinkedList<int> dll = new DoublyLinkedList<int> (values);
dll.AddAfter(dll.Tail, toAddValue);
PexAssert.AreEqual(toAddValue, dll.Tail.Value);
PexAssert.AreEqual(values[values.Count - 1], dll.Tail.Previous.Value);
}
示例9: Contains
public void Contains()
{
DoublyLinkedList<int> list = new DoublyLinkedList<int>();
list.Add(3);
list.Add(5);
list.Add(7);
bool isTrue = list.Contains(3);
Assert.AreEqual(true, isTrue);
}
示例10: Clear
public void Clear()
{
DoublyLinkedList<int> list = new DoublyLinkedList<int>();
list.Add(3);
list.Add(5);
list.Add(7);
list.Clear();
list.ShouldBeEmpty();
}
示例11: CopyToWithLessSpaceInTheArray
public void CopyToWithLessSpaceInTheArray()
{
DoublyLinkedList<int> list = new DoublyLinkedList<int>();
int[] array = new int[3];
list.Add(3);
list.Add(5);
list.Add(7);
list.CopyTo(array, 2);
}
示例12: CopyTo
public void CopyTo()
{
DoublyLinkedList<int> list = new DoublyLinkedList<int>();
int[] array = new int[3];
list.Add(3);
list.Add(5);
list.Add(7);
list.CopyTo(array, 0);
}
示例13: CopyTo
public void CopyTo()
{
var list = new DoublyLinkedList<int>(new[] { 1, 2, 3 });
var array = new int[4];
list.CopyTo(array, 1);
CollectionAssert.AreEqual(new[] {0, 1, 2, 3}, array);
}
示例14: AddAfterTailTest
public void AddAfterTailTest()
{
DoublyLinkedList<int> dll = new DoublyLinkedList<int> {10};
dll.AddAfter(dll.Head, 20);
Assert.AreEqual(20, dll.Tail.Value);
Assert.AreEqual(10, dll.Tail.Previous.Value);
}
示例15: ClassInitializer
public static void ClassInitializer(TestContext context)
{
head = new DoublyLinkedListNode<int>(-1);
doublyLinkedList= new DoublyLinkedList<int>(head);
doublyLinkedList.Add(4);
doublyLinkedList.Add(41);
doublyLinkedList.Add(54);
doublyLinkedList.Add(9);
}