當前位置: 首頁>>代碼示例>>C#>>正文


C# SinglyLinkedLists.SinglyLinkedListNode類代碼示例

本文整理匯總了C#中SinglyLinkedLists.SinglyLinkedListNode的典型用法代碼示例。如果您正苦於以下問題:C# SinglyLinkedListNode類的具體用法?C# SinglyLinkedListNode怎麽用?C# SinglyLinkedListNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SinglyLinkedListNode類屬於SinglyLinkedLists命名空間,在下文中一共展示了SinglyLinkedListNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SinglyLinkedList

        // READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
        // list [i] = value; i is new list q is old list
        public string this[int i]
        {
            get { return this.ElementAt(i); }
            set {
                var placeHolderList = new SinglyLinkedList();

                for (var q = 0; q < this.Count(); q++)
                {
                   if (q==i)
                    {
                        placeHolderList.AddLast(value);
                    }
                    else
                    {
                        placeHolderList.AddLast(this.ElementAt(q));
                    }
                }

                first_node = new SinglyLinkedListNode(placeHolderList.First());
                for (var w = 1; w < placeHolderList.Count(); w++)
                {
                    this.AddLast(placeHolderList.ElementAt(w));
                }
            }
        }
開發者ID:Naa2e,項目名稱:csharplinkedlists,代碼行數:27,代碼來源:SinglyLinkedList.cs

示例2: AddAfter

        public void AddAfter(string existingValue, string value)
        {
            SinglyLinkedListNode CurrentNode = firstNode;
            SinglyLinkedListNode NodeToInsert = new SinglyLinkedListNode(value);
            if (ExistingValueExists(existingValue))
            {
                while (CurrentNode != null)
                {
                    if (CurrentNode.Value == existingValue)
                    {
                        NodeToInsert.Next = CurrentNode.Next;
                        CurrentNode.Next = NodeToInsert;
                        CurrentNode = NodeToInsert;
                    }
                    else
                    {
                        CurrentNode = CurrentNode.Next;
                    }

                }
            }
            else
            {
                throw new ArgumentException();
            }
        }
開發者ID:tombler,項目名稱:LinkedListCohortJuniper,代碼行數:26,代碼來源:SinglyLinkedList.cs

示例3: SinglyLinkedList

        // READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
        public string this[int index]
        {
            get
            {
                return this.ElementAt(index);
            }
            set
            {
                var placeholder = new SinglyLinkedList();
                for(var j = 0; j < this.Count(); j++)
                {
                    if (j == index)
                    {
                        placeholder.AddLast(value);
                    } else
                    {
                        placeholder.AddLast(this.ElementAt(j));
                    }
                }
                first_node = new SinglyLinkedListNode(placeholder.First());

                for(var k = 1; k < placeholder.Count(); k++ )
                {
                    this.AddLast(placeholder.ElementAt(k));
                }
               }
        }
開發者ID:colecathey,項目名稱:csharplinkedlists,代碼行數:28,代碼來源:SinglyLinkedList.cs

示例4: NodeEqualityWithEqualValues

 public void NodeEqualityWithEqualValues()
 {
     SinglyLinkedListNode node1 = new SinglyLinkedListNode("foo");
     SinglyLinkedListNode node2 = new SinglyLinkedListNode("foo");
     Assert.AreEqual(node1, node2); // Equivalent to: Assert.IsTrue(node1.Equals(node2));
     // When you create your own types, you should override Equals. -- quote from the docs
 }
開發者ID:tombler,項目名稱:LinkedListCohortJuniper,代碼行數:7,代碼來源:UnitTestSinglyLinkedListNode.cs

示例5: AddAfter

 public void AddAfter(string existingValue, string value)
 {
     /* if (last.Value == existingValue)
     {
         AddLast(value);
     } */
     SinglyLinkedListNode adding = new SinglyLinkedListNode(value);
     SinglyLinkedListNode test = first;
     while (true) {
         if (test == null)
         {
             throw new ArgumentException();
         }
         if (test != null)
         {
             if (test.Value == existingValue)
             {
                 adding.Next = test.Next;
                 test.Next = adding;
                 count++;
                 break;
             }
             test = test.Next;
         }
     }
 }
開發者ID:C-Stein,項目名稱:LinkedListCohortJuniper,代碼行數:26,代碼來源:SinglyLinkedList.cs

示例6: SinglyLinkedList

        // READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
        public string this[int i]
        {
            get { return this.ElementAt(i); }
            set
            {
                var newList = new SinglyLinkedList();

                for (var x = 0; x < this.Count(); x++)
                {
                    if (x == i)
                    {
                        newList.AddLast(value);
                    }
                    else
                    {
                        newList.AddLast(this.ElementAt(x));
                    }
                }
                    first_node = new SinglyLinkedListNode(newList.First());
                    for (var w = 1; w < newList.Count(); w++)
                {
                    this.AddLast(newList.ElementAt(w));

                }
                }
        }
開發者ID:marsette25,項目名稱:csharplinkedlists,代碼行數:27,代碼來源:SinglyLinkedList.cs

示例7: AddLast

 public void AddLast(string value)
 {
     SinglyLinkedListNode newNode = new SinglyLinkedListNode(value);
     if (firstNode == null) firstNode = newNode;
     else LastNode().Next = newNode;
     count++;
 }
開發者ID:NewEvolution,項目名稱:LinkedListCohortJuniper,代碼行數:7,代碼來源:SinglyLinkedList.cs

示例8: AddFirst

 public void AddFirst(string value)
 {
     SinglyLinkedListNode newNode = new SinglyLinkedListNode(value);
     newNode.Next = firstNode;
     firstNode = newNode;
     count++;
 }
開發者ID:NewEvolution,項目名稱:LinkedListCohortJuniper,代碼行數:7,代碼來源:SinglyLinkedList.cs

示例9: AddAfter

 public void AddAfter(string existingValue, string value)
 {
     if (ElementAt(-1) == existingValue)
     {
         AddLast(value);
     }
     else
     {
         SinglyLinkedListNode current = firstNode;
         bool found = false;
         while (!current.IsLast())
         {
             if (current.Value == existingValue)
             {
                 SinglyLinkedListNode new_node = new SinglyLinkedListNode(value);
                 SinglyLinkedListNode old_next = current.Next;
                 new_node.Next = old_next;
                 current.Next = new_node;
                 found = true;
                 break;
             }
             current = current.Next;
         }
         if (!found)
         {
             throw new ArgumentException();
         }
     }
 }
開發者ID:rob1nburt0n,項目名稱:LinkedListCohortJuniper,代碼行數:29,代碼來源:SinglyLinkedList.cs

示例10: AddAfter

        public void AddAfter(string existingValue, string value)
        {
            var node = this.first_node;
            var inputValue = IndexOf(existingValue);
            var value2Add = new SinglyLinkedListNode(value);

            if (IndexOf(existingValue) == -1)
            {
                throw new ArgumentException();
            }

            for (var i = 0; i < this.Count(); i++)
            {

                if (node.Value == existingValue)
                {
                    // gets the index of the found node
                    var foundPosition = node;

                    // set the pointer for the new node
                    value2Add.Next = foundPosition.Next;

                    // set the new value for after foundPosition
                    foundPosition.Next = value2Add;
                }
                else if (!node.IsLast())
                {
                    this.AddLast(value2Add.Value);
                }

                node = new SinglyLinkedListNode(value);
            }
        }
開發者ID:Rittycheriah,項目名稱:csharplinkedlists,代碼行數:33,代碼來源:SinglyLinkedList.cs

示例11: SinglyLinkedList

        // READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
        public string this[int i]
        {
            //uses the ElementAt function to get value (saves you from duplicating your code)
            get { return this.ElementAt(i); }
            set
            {
                //using a placeholder list helps save the values in order without having to do voodoo with the pointers
                var placeholderList = new SinglyLinkedList();
                for (var q = 0; q < this.Count(); q++)
                {
                    //if this is the place where you need to exchange the value, insert it here
                    if (q == i)
                    {
                        placeholderList.AddLast(value);
                    }
                    //otherwise, insert the value that was preexisting in the list
                    else
                    {
                        placeholderList.AddLast(this.ElementAt(q));
                    }
                }

                //now swap out the values in the placeholder list into the real list.
                //first swap the first value to clear out the old list
                first_node = new SinglyLinkedListNode(placeholderList.First());
                //then loop through the placeholder list and add the values to the real list in order
                for (var w = 1; w < placeholderList.Count(); w++)
                {
                    this.AddLast(placeholderList.ElementAt(w));
                }
            }
        }
開發者ID:Anne0011,項目名稱:csharplinkedlists,代碼行數:33,代碼來源:SinglyLinkedList.cs

示例12: SinglyLinkedList

        // READ: http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx
        public string this[int i]
        {
            get { return this.ElementAt(i); }
            set
            {
                var copy_of_list = new SinglyLinkedList();
                for (var j = 0; j < this.Count(); j++)
                {
                    if (j == i)
                    {
                        copy_of_list.AddLast(value);
                    }
                    else
                    {
                        copy_of_list.AddLast(this.ElementAt(j));
                    }
                }

                first_node = new SinglyLinkedListNode(copy_of_list.First());
                for (var o = 1; o < copy_of_list.Count(); o++)
                {
                    this.AddLast(copy_of_list.ElementAt(o));
                }
            }
        }
開發者ID:Rittycheriah,項目名稱:csharplinkedlists,代碼行數:26,代碼來源:SinglyLinkedList.cs

示例13: NodeLastWhenLast

 public void NodeLastWhenLast()
 {
     SinglyLinkedListNode node1 = new SinglyLinkedListNode("foo");
     SinglyLinkedListNode node2 = new SinglyLinkedListNode("bar");
     node1.Next = node2;
     Assert.IsFalse(node1.IsLast());
 }
開發者ID:MKergosien,項目名稱:LinkedListCohortJuniper,代碼行數:7,代碼來源:UnitTestSinglyLinkedListNode.cs

示例14: AddAfter

        public void AddAfter(string existingValue, string value)
        {
            if (ElementAt(-1) == existingValue)
            {
                AddLast(value);
            }
            else
            {
                SinglyLinkedListNode prevNode = firstNode;
                bool found = false;
                while (!prevNode.IsLast())
                {
                    if (prevNode.Value == existingValue)
                    {
                        SinglyLinkedListNode newNode = new SinglyLinkedListNode(value);
                        SinglyLinkedListNode oldNext = prevNode.Next;
                        newNode.Next = oldNext;
                        prevNode.Next = newNode;

                        found = true;
                        count++;
                        break;
                    }
                    prevNode = prevNode.Next;
                }

                if (!found)
                {
                    throw new ArgumentException();
                }
            }
        }
開發者ID:rachyllmorgan,項目名稱:LinkedListCohortJuniper,代碼行數:32,代碼來源:SinglyLinkedList.cs

示例15: NodeEqualityIgnoresNext

 public void NodeEqualityIgnoresNext()
 {
     SinglyLinkedListNode node1 = new SinglyLinkedListNode("foo");
     node1.Next = new SinglyLinkedListNode("bob");
     SinglyLinkedListNode node2 = new SinglyLinkedListNode("foo");
     node2.Next = new SinglyLinkedListNode("sally");
     Assert.AreEqual(node1, node2);
 }
開發者ID:MKergosien,項目名稱:LinkedListCohortJuniper,代碼行數:8,代碼來源:UnitTestSinglyLinkedListNode.cs


注:本文中的SinglyLinkedLists.SinglyLinkedListNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。