当前位置: 首页>>代码示例>>C#>>正文


C# SinglyLinkedList类代码示例

本文整理汇总了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 + " ");
            }
        }
开发者ID:Nezhdetov,项目名称:Software-University,代码行数:33,代码来源:Program.cs

示例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);
        }
    }
开发者ID:bobosam,项目名称:DataStructures,代码行数:28,代码来源:SinglyLinkedListTEst.cs

示例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));
 }
开发者ID:evilz,项目名称:algorithm-datastructure,代码行数:7,代码来源:SimpleLinkedListTests.cs

示例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");
 }
开发者ID:joshimoo,项目名称:JamLib,代码行数:7,代码来源:SinglyLinkedListTests.cs

示例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));
        }
开发者ID:anichalakova,项目名称:DataStructuresHWs,代码行数:28,代码来源:Program.cs

示例6: BeginTestMethod

 public void BeginTestMethod()
 {
     target = new SinglyLinkedList<int>();
     Assert.AreEqual(target.Leng, 0);
     target.Add(2);
     target.Add(3, 1);
     target.AddLast(5);
 }
开发者ID:hirotk,项目名称:Algorithm,代码行数:8,代码来源:SinglyLinkedListTest.cs

示例7: SinglyLinkedListIntIsNull

 public void SinglyLinkedListIntIsNull()
 {
     _singlyLinkedListInt = null;
     _index = 5;
     int expected = 0;
     var actual = _linkedListOperationsInt.GetNthElementFromLast(_singlyLinkedListInt, _index);
     Assert.AreEqual(expected, actual);
 }
开发者ID:Dario80,项目名称:Code4Fun_Totaro_2015-06-24,代码行数:8,代码来源:LinkedListOperationsTests.cs

示例8: SetupUnitTests

        public void SetupUnitTests()
        {
            _linkedListOperationsInt = new LinkedListOperations<int>();
            _singlyLinkedListInt = new SinglyLinkedList<int>();

            _linkedListOperationsString = new LinkedListOperations<string>();
            _singlyLinkedListString = new SinglyLinkedList<string>();
        }
开发者ID:Dario80,项目名称:Code4Fun_Totaro_2015-06-24,代码行数:8,代码来源:LinkedListOperationsTests.cs

示例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;
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:9,代码来源:SinglyLinkedListFactory.cs

示例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));
        }
开发者ID:ChrisAnn,项目名称:BackToBasics,代码行数:9,代码来源:SinglyLinkedListTests.cs

示例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);
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:9,代码来源:SinglyLinkedListTest.cs

示例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));
        }
开发者ID:evilz,项目名称:algorithm-datastructure,代码行数:9,代码来源:SimpleLinkedListTests.cs

示例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");
        }
开发者ID:joshimoo,项目名称:JamLib,代码行数:10,代码来源:SinglyLinkedListTests.cs

示例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));
        }
开发者ID:ChrisAnn,项目名称:BackToBasics,代码行数:10,代码来源:SinglyLinkedListTests.cs

示例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");
        }
开发者ID:joshimoo,项目名称:JamLib,代码行数:10,代码来源:SinglyLinkedListTests.cs


注:本文中的SinglyLinkedList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。