• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SinglyLinkedList类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SinglyLinkedList的典型用法代码示例。如果您正苦于以下问题:C# SinglyLinkedList类的具体用法?C# SinglyLinkedList怎么用?C# SinglyLinkedList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SinglyLinkedList类属于命名空间,在下文中一共展示了SinglyLinkedList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: AddAfterMiddleNodeTest

        public void AddAfterMiddleNodeTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};

            sll.AddAfter(sll.Head.Next, 25);

            Assert.AreEqual(25, sll.Head.Next.Next.Value);
            Assert.AreEqual(30, sll.Head.Next.Next.Next.Value);
            Assert.AreEqual(4, sll.Count);
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:10,代码来源:SinglyLinkedListTest.cs


示例17: AddAfterTailTest

        public void AddAfterTailTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20};

            sll.AddAfter(sll.Tail, 30);

            Assert.AreEqual(30, sll.Tail.Value);
            Assert.AreEqual(30, sll.Head.Next.Next.Value);
            Assert.AreEqual(3, sll.Count);
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:10,代码来源:SinglyLinkedListTest.cs


示例18: Append_single_node_to_end_of_multiple_item_list

        public void Append_single_node_to_end_of_multiple_item_list()
        {
            var head = new ListNode<int>(12) { Next = new ListNode<int>(77) };
            var list = new SinglyLinkedList<int>(head);

            var node = new ListNode<int>(42);
            list.Append(node);

            Assert.That(list.Length, Is.EqualTo(3));
            Assert.That(list.Head.Next.Next, Is.EqualTo(node));
        }
开发者ID:ChrisAnn,项目名称:BackToBasics,代码行数:11,代码来源:SinglyLinkedListTests.cs


示例19: AddAfterOnlyOneNodeInListTest

        public void AddAfterOnlyOneNodeInListTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10};

            sll.AddAfter(sll.Head, 20);

            Assert.AreEqual(20, sll.Tail.Value);
            Assert.AreEqual(10, sll.Head.Value);
            Assert.AreEqual(20, sll.Head.Next.Value);
            Assert.AreEqual(2, sll.Count);
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:11,代码来源:SinglyLinkedListTest.cs


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Site类代码示例发布时间:2022-05-24
下一篇:
C# SingleOrder类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap