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


C# SinglyLinkedList.AddFirst方法代码示例

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


在下文中一共展示了SinglyLinkedList.AddFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFirstOnEmptyList

 public void AddFirstOnEmptyList()
 {
     SinglyLinkedList list = new SinglyLinkedList();
     list.AddFirst("foo");
     string[] expected = new string[] { "foo" };
     CollectionAssert.AreEqual(expected, list.ToArray());
 }
开发者ID:marsette25,项目名称:csharplinkedlists,代码行数:7,代码来源:UnitTestSinglyLInkedList.cs

示例2: AddFirstOnLongerList

 public void AddFirstOnLongerList()
 {
     SinglyLinkedList list = new SinglyLinkedList();
     list.AddLast("foo");
     list.AddLast("bar");
     list.AddFirst("grille");
     var expected = new string[] { "grille", "foo", "bar" };
     CollectionAssert.AreEqual(expected, list.ToArray());
 }
开发者ID:marsette25,项目名称:csharplinkedlists,代码行数:9,代码来源:UnitTestSinglyLInkedList.cs

示例3: AddFirst

 public void AddFirst(string value)
 {
     //if this is the first node, this is just an assignment
     if (this.First() == null)
     {
         first_node = new SinglyLinkedListNode(value);
     }
     else
     {
         //create a placeholder list to store the values in order.
         var placeholderList = new SinglyLinkedList();
         placeholderList.AddFirst(value);
         for (var i = 0; i < this.Count(); i++)
         {
             placeholderList.AddLast(this.ElementAt(i));
         }
         //now reassign the values to the current linked list in order (this.First() etc)
         first_node = new SinglyLinkedListNode(placeholderList.First());
         for (var q = 1; q < placeholderList.Count(); q++ )
         {
             this.AddLast(placeholderList.ElementAt(q));
         }
     }
 }
开发者ID:katerebekah,项目名称:csharplinkedlists,代码行数:24,代码来源:SinglyLinkedList.cs

示例4: testIndexOfNodeInFirst

 public void testIndexOfNodeInFirst()
 {
     SinglyLinkedList list = new SinglyLinkedList();
     list.AddFirst("node1");
     Assert.AreEqual(0, list.IndexOf("node1"));
 }
开发者ID:AustinScott3573,项目名称:LinkedListCohortJuniper,代码行数:6,代码来源:UnitTestSinglyLInkedList.cs

示例5: testIndexOfNodeForMultipleItems

 public void testIndexOfNodeForMultipleItems()
 {
     SinglyLinkedList list = new SinglyLinkedList();
     list.AddFirst("node1");
     list.AddLast("node2");
     Assert.AreEqual(1, list.IndexOf("node2"));
 }
开发者ID:AustinScott3573,项目名称:LinkedListCohortJuniper,代码行数:7,代码来源:UnitTestSinglyLInkedList.cs

示例6: AddFirst

        public void AddFirst(string value)
        {
            if (this.First() == null)
            {
                first_node = new SinglyLinkedListNode(value);
            }
            else
            {
                var newFirstNode = new SinglyLinkedListNode(value);
                var placeHolderList = new SinglyLinkedList();
                placeHolderList.AddFirst(newFirstNode.Value);
                for (var i = 0; i < this.Count(); i++)
                {
                    placeHolderList.AddLast(this.ElementAt(i));
                }
                first_node = new SinglyLinkedListNode(placeHolderList.First());
                for (var q = 1; q < placeHolderList.Count(); q++)
                {
                    this.AddLast(placeHolderList.ElementAt(q));
                }

            }
        }
开发者ID:LandoB,项目名称:csharplinkedlists,代码行数:23,代码来源:SinglyLinkedList.cs


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