Home

Linked Lists

   

The .NET Framework's Linked List

   

Introduction

A linked list is a collection with the following rules:

  • Each item in the list is called a node (this is not an actual rule but a habit or a suggestion)

Node

  • If the list is empty, it may have one item referred to as null
  • If the list was just empty, when a new node is added, that node becomes the first and last item
  • If the list has only one node, that node represents the first and the last item

    Node

  • If the list contains at least one node, whenever a new node is added, that new node is positioned as the last in the list. This is because the new node is added next to the existing node
  • If the list contains more than one node, each item holds a reference to the object next to it

Nodes of a Linked List

In reality, there are various types of linked lists. A singly linked list is a one-way directional list where each item points (only) to the item next to it (in a somewhat right direction). The description we just gave is conform to a singly linked list. Another type is the doubly linked list:

  • Each item in the list is called a node (again, this is not a real rule)
  • If the list is empty, it may have one item referred to as null or two items referred to as nulls
  • If a new node is added to an empty list, that node is added as the first in the collection
  • If the list contains one node, that node has two references to itself: one reference as the next and the other reference as its previous
  • If the list contains two nodes:
    • One node is the first. That first node holds a reference to the other node as its next
    • The other node is the last. That last node holds a reference to the first node as its previous item
  • If the list contains more than two nodes:
    • The first node holds a reference to the next node (in the right direction)
    • The last node holds a reference to the node previous to it (in the left direction)
    • Each node holds two references: one reference to the previous node and one reference to the next node

Nodes of a Linked List

The last type of linked list is called a circular linked list. This list is primarily created as either a singly linked list or a doubly linked list:

  • In a circular singly linked list, the list primarily follows the rules of a singly linked list. then:
    • If the list has two nodes, the first node holds a reference to the other node as its next and its previous node
    • If the list has more than one node:
      • The first node holds a reference to the last node as its previous object
      • The last node holds a reference to first node as its next

Circular Singly Linked List

  • In a doubly linked list, the list includes the rules of the doubly linked list and combines with those of the circular singly linked list:
    • The first node has a reference to the last node as its previous node
    • The last node has a reference to the first node as its next node
    • Each node has two references: its previous and its next nodes

Circular Doubly Linked List

Creating a Linked List

Although you can create a linked list collection class from scratch, to assist you, the .NET Framework provides a class named LinkedList and that is a member of the System.Collections.Generic namespace. LinkedList is a generic collection class with three constructors. The default constructor allows you to create an empty linked list. Here is an example of using it:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)
    End Sub
End Class

Another constructor allows you to create a linked using an existing list. Its syntax is:

Public Sub New (collection As IEnumerable(Of T))

The argument can be a variable from any class that implements the IEnumerable(Of T) interface. Here is an example of using this second constructor:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
    End Sub
End Class

Fundamental Operations on a Linked List

 

Introduction to a Node as an Object

As mentioned already, it is a tradition to call an item of a linked list a node. To define a node as a true object, the .NET Framework provides the LinkedListNode sealed class:

Public NotInheritable Class LinkedListNode(Of T)

This class has only properties, no methods.

The Number of Nodes of a List

The LinkedList class starts as follows:

Public Class LinkedList(Of T)
    Implements ICollection(Of T), IEnumerable(Of T),
    ICollection, IEnumerable, ISerializable, IDeserializationCallback

As you can see, the LinkedList class implements the ICollection interface. This gives it a Count property that produces the number of nodes. Here is an example of accessing it:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)

        MsgBox("There are " & CStr(Numbers.Count) & " numbers in the list",
               MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
               "Linked List")
    End Sub
End Class

Linked List

Adding a Node

The primary operation to perform on a linked list is to add a new node to it. To support it, the LinkedList class is equipped with various methods. One of them is named AddLast that is overloaded in two versions. One of them uses the following syntax:

Public Function AddLast(value As T) As LinkedListNode(Of T)

This method expects the new value as argument. Here is an example of calling it:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                            ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)

        Numbers.AddLast(148.24)
    End Sub
End Class

Another version of this method is:

Public Sub AddLast(node As LinkedListNode(Of T))

This version expects a LinkedListNode object as argument. Here is an example of calling it:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                         ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)

        Numbers.AddLast(Number)
    End Sub
End Class

In the same way, you can use this method to add new items. Here are examples:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)

        Numbers.AddLast(Number)

        Number = New LinkedListNode(Of Double)(35.75)
        Numbers.AddLast(Number)

        Number = New LinkedListNode(Of Double)(2222.06)
        Numbers.AddLast(Number)

        Number = New LinkedListNode(Of Double)(4.19)
        Numbers.AddLast(Number)

        Number = New LinkedListNode(Of Double)(66.18)
        Numbers.AddLast(Number)
    End Sub
    
End Class
 
 
 

Looking for a Node

 

Introduction

Because the LinkedList implements the ICollection interface, it inherits the Contains method. As a reminder, its syntax is:

Public Function Contains(value As T) As Boolean

This method checks whether the linked list contains the (a) node that has the value passed as argument. If that node is found, the method returns true. Otherwise it returns false. Here is an example of calling it:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        Numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(35.75)
        Numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(2222.06)
        Numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(4.19)
        Numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(66.18)
        Numbers.AddFirst(number)

        If Numbers.Contains(2222.06) = True Then
            MsgBox("The list contains 2222.06.",
                        MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                        "Linked List")
        Else
            MsgBox("There is no such a number in the list.",
                        MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                        "Linked List")
        End If
    End Sub

End Class

This method works only if the type of the node is able to perform the comparison for equality. If you are using values of primitive types (int, char, double, DateTime, etc) or string, the method would work fine. If you are using your own class, make sure you override the Equals() method.

Finding a Node

While the Contains() method is used to look for a value in a linked list, it only lets you know whether the value was found. If you want to get the actual node that has that value, you can call the Find() method. Its syntax is:

Public Function Find(value As T) As LinkedListNode(Of T)

When this method is called, it starts looking for the value in the linked list. If it finds it, it returns its node. If there is more than one node with that value, the method returns only the first node that has that value. Here is an example of calling this method:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                         ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        numbers.AddFirst(Number)

        number = New LinkedListNode(Of Double)(35.75)
        Numbers.AddFirst(Number)

        number = New LinkedListNode(Of Double)(2222.06)
        Numbers.AddFirst(Number)

        Numbers.AddFirst(2747.06)

        number = New LinkedListNode(Of Double)(4.19)
        Numbers.AddFirst(Number)

        number = New LinkedListNode(Of Double)(66.18)
        Numbers.AddFirst(Number)

        If Numbers.Find(2747.06) Is Nothing Then
            MsgBox("2747.06 was found in the list.",
                        MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                        "Linked List")
        Else
            MsgBox("2747.06 is nowhere in the list.",
                        MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                        "Linked List")
        End If
    End Sub

End Class

Linked List

If the list contains more than one node that has the value but you prefer to use the last node, you can call the FindLast() method.

Public Function FindLast(value As T) As LinkedListNode(Of T)

Once again, remember that these two methods are ready to work on primitive types. If you are using your own class for the type of node, you should (must) override the Equals() method.

Getting Each Node

As you can see, the LinkedList class doesn't implement the IList interface, which means it doesn't have an Item property. As we have seen with the AddLast() method and as we will see in the next sections, each method used to add a node is provided in two versions. One of the versions returns a LinkedListNode object. This means that, when performing an addition operation, you can get the returned value and do what you want with it.

The class LinkedList class implements the IEnumerable interface. This makes it possible to use For Each to get to access each node. This can be done as follows:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)

        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)

        Numbers.AddFirst(Number)

        For Each Nbr As Double In Numbers
            MsgBox(CStr(Nbr),
                   MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                   "Linked List")
        Next
    End Sub
    
End Class

The Value of a Node

Probably the most important aspect of a node is its value. To support it, the LinkedListNode class has a property named Value:

Public Property Value As T
    Get
    Set

Because this is a read-write property, you can use its write-accessory to specify or change its value. On the other hand, you can access the value of a node using this property.

Navigating Among the Nodes

 

The First and the Last Nodes

As mentioned already, a linked list has a first and a last nodes (some people or documentations call them the head and the tail). To identify the first node, the LinkedList class is equippped with a read-only property named First. Its syntax is:

Public ReadOnly Property First As LinkedListNode(Of T)
    Get

The last node is represented by a read-only property of the same name and that, too, is a LinkedListNode object:

Public ReadOnly Property Last As LinkedListNode(Of T)
    Get

Here are examples of accessing these properties:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)

        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        Numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(35.75)
        Numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(2222.06)
        Numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(4.19)
        Numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(66.18)
        Numbers.AddFirst(Number)

        MsgBox("The value of the first node is " & Numbers.First.Value,
                       MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                       "Linked List")
        MsgBox("The value of the last node is " & Numbers.Last.Value,
                       MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
                       "Linked List")
    End Sub
    
End Class

The Next and Previous Nodes

To access a node that is next to an existing node, you must first know what node is used as reference. To let you access the next node, the LinkedListNode class is equipped with a read-only property named Next:

Public ReadOnly Property Next As LinkedListNode(Of T)
    Get

To let you access the node previous to an existing one, the LinkedListNode class is equipped with the read-only Previous property:

Public ReadOnly Property Previous As LinkedListNode(Of T)
    Get

Remember that in both cases, you need a node as reference.

Creating Nodes

 

Adding the First Node

When dealing with a linked list, you have many options on how to add a new node. As mentioned already, a linked list has a first node, a last node, and one or more nodes between them. All nodes have and use some references with regards to the node(s) close to them. Based on this, when adding a new node, you have to specify whether you want it as the first node, the last node, the node before a certain node, or the node after a certain one. The LinkedList class easily supports all these operations with very little effort on your part.

We saw that you could call the AddFirst() method to add a new node. In reality, there is no such a thing as simply adding a new node to a linked list. When a linked list has just been created and it is empty, it holds a reference to a null node. There is nothing you can do with that node and you don't need to do anything with it. To start adding nodes, you have the option of setting it as the first or the last item. This would not make any difference because there is no other node in the list.

After adding a node, it becomes a reference that new nodes can use. If you call the AddFirst() method, the new node would be added before any existing node in the collection.

Adding the Last Node

By contrast, you can call a method named AddLast. It is overloaded with versions whose syntaxes are:

Public Function AddLast(value As T) As LinkedListNode(Of T)
Public Sub AddLast(node As LinkedListNode(Of T))

When you call this method, the value or node you pass will be added as the last item in the list. Here is an example:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                           ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(35.75)
        numbers.AddFirst(Number)

        numbers.AddLast(2747.06)

        Number = New LinkedListNode(Of Double)(2222.06)
        numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(4.19)
        numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(66.18)
        numbers.AddFirst(Number)

        For Each Dbl As Double In Numbers
            LbxLinkedList.Items.Add(Dbl)
        Next
    End Sub
End Class

Linked List

Inserting a Node Before a Referenced One

A linked list supports the concept of inserting a node but not exactly like traditional collections do it. With a linked list, you must add a node before or after an existing node used as reference.

Behind the scenes, before inserting a node, you must identify the position where you want to put it. That is, you must identify what node you will use as reference:

Inserting a New node Before a Node

In this case, you want to insert a new node before the Other Node. Behind the scenes, the reference between the two existing nodes must be brocken. Then the new node points to the Other Node as its next and the Other Node points at the New Node as its previous:

Inserting a New node Before a Node

After the new node has been added, it must point to the previous node (Some Node in our example) as its previous item. The previous node (Some Node in our example) must now point to the new node as its next item:

Inserting a New node Before a Node

As you may imagine, to insert a node, you must provide two pieces of information: a reference to the node that will succeed the new node, and the new node (or its value). If the referenced node is the first item of the list, the new node would become the new first object.

To assist you with this operation, the LinkedList class provides a method named AddBefore. This method is overloaded with two versions whose syntaxes are:

Public Sub AddBefore(node As LinkedListNode(Of T), _
		     newNode As LinkedListNode(Of T) _
)
Public Function AddBefore(node As LinkedListNode(Of T), _
    			  value As T _
) As LinkedListNode(Of T)

In both cases, you pass a first argument as an existing node. In the first case, you must pass the LinkedListNode object that will be inserted the node. Here is an example:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(35.75)
        numbers.AddFirst(number)

        numbers.AddLast(2747.06)

        Dim Number222206 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(2222.06)
        numbers.AddLast(number222206)

        number = New LinkedListNode(Of Double)(4.19)
        numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(66.18)
        numbers.AddBefore(number222206, number)

        number = New LinkedListNode(Of Double)(275.775)
        numbers.AddLast(number)

        For Each Dbl As Double In Numbers
            LbxLinkedList.Items.Add(Dbl)
        Next
    End Sub

End Class

Linked List

In the second version, you directly pass the value to be positioned before node.

Inserting a Node After a Referenced One

Instead of inserting a node before an existing one, you can add it after one. The approach is logically the same as inserting a node before another, except that the sequence is reversed. First identify the node that will be used as reference. Start the process to add the new node after that one. Behind the scenes, the referenced node will point to the new node as its next and the new node will point to the existing node as its previous:

Inserting a New node After an Existing Node

After the new node as been added, it will point to the node after it as its next. The other node will point to the new node as its previous:

Inserting a New node After an Existing Node

If the new node is added after the last node, the new node will become the new last node.

To let you insert a node after an existing node, the LinkedList class is equipped with a method named AddAfter. It comes in two versions and their syntaxes are:

Public Sub AddAfter ( _
    node As LinkedListNode(Of T), _
    newNode As LinkedListNode(Of T) _
)
Public Function AddAfter ( _
    node As LinkedListNode(Of T), _
    value As T _
) As LinkedListNode(Of T)

The arguments follow the same description as the AddBefore() method, only in reverse. Here is an example:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        values.Add(84.597)
        values.Add(6.47)
        values.Add(2747.06)
        values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        Numbers.AddFirst(Number)

        Dim Number3575 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(35.75)
        numbers.AddFirst(number3575)

        numbers.AddLast(2747.06)

        Dim Number222206 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(2222.06)
        numbers.AddLast(number222206)

        number = New LinkedListNode(Of Double)(4.19)
        numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(66.18)
        numbers.AddBefore(number222206, number)

        number = New LinkedListNode(Of Double)(275.775)
        numbers.AddAfter(number3575, number)

        For Each Dbl As Double In Numbers
            LbxLinkedList.Items.Add(Dbl)
        Next
    End Sub

End Class

Linked List

Deleting Nodes

 

Deleting the First or Last Node

When it comes time to delete a node, you have many options, such as deleting the first or the last node of the list. To let you delete the first node, the LinkedList class provides the RemoveFirst() method. Its syntax is:

Public Sub RemoveFirst

As you can see, this method takes no argument. When it is called:

  • If the list is empty, the compiler throws an InvalidOperationException exception:

Invalid Operation Exception

  • If the list contains one node, that node gets deleted
  •  If the list contains more than one node, the first one gets deleted

To delete the last node, you can call the RemoveLast() method whose syntax is:

Public Sub RemoveLast

This method follows the same logic as the RemoveFirst() method, only in reverse. Here are examples of calling these methods:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        numbers.AddFirst(number)

        Dim Number3575 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(35.75)
        numbers.AddFirst(Number3575)

        numbers.AddLast(2747.06)

        Dim Number222206 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(2222.06)
        numbers.AddLast(Number222206)

        number = New LinkedListNode(Of Double)(4.19)
        numbers.AddFirst(number)

        number = New LinkedListNode(Of Double)(66.18)
        numbers.AddBefore(Number222206, number)

        number = New LinkedListNode(Of Double)(275.775)
        numbers.AddAfter(Number3575, number)

        For Each Dbl As Double In Numbers
            lbxLinkedListOriginal.Items.Add(Dbl)
        Next

        numbers.RemoveFirst()
        numbers.RemoveLast()

        For Each Dbl As Double In Numbers
            lbxLinkedListOther.Items.Add(Dbl)
        Next
    End Sub

End Class

Linked List

Removing a Node by Value

There are two ways you can delete an item inside the collection. This can be done using the Remove() method. It comes in two versions. If you know the exact value of the item you want to remove, you can call the follwing version of that method:

Public Function Remove(value As T) As Boolean

When calling this method, pass the value to delete. The compiler would first look for a node that has that value:

  • If there is a node with that value in the list, it would be deleted
  • If there is no node with that value, nothing would happen (the compiler would not throw an exception)

An alternative is to delete a node based on its reference. To do this, use the following version:

Public Sub Remove(node As LinkedListNode(Of T))

When calling this method, pass a reference to the node you want to delete. Here is an example:

Public Class Exercise

    Private Sub BtnLinkedList_Click(ByVal sender As System.Object,
                                    ByVal e As System.EventArgs) Handles BtnLinkedList.Click
        Dim Values As List(Of Double) = New List(Of Double)
        Values.Add(84.597)
        Values.Add(6.47)
        Values.Add(2747.06)
        Values.Add(282.924)

        Dim Numbers As LinkedList(Of Double) = New LinkedList(Of Double)(Values)
        Dim Number As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(148.24)
        Numbers.AddFirst(Number)

        Dim Number3575 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(35.75)
        Numbers.AddFirst(number3575)

        Numbers.AddLast(2747.06)

        Dim Number222206 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(2222.06)
        Numbers.AddLast(number222206)

        Number = New LinkedListNode(Of Double)(4.19)
        Numbers.AddFirst(Number)

        Number = New LinkedListNode(Of Double)(66.18)
        Numbers.AddBefore(number222206, Number)

        Dim Number275775 As LinkedListNode(Of Double) = New LinkedListNode(Of Double)(275.775)
        Numbers.AddAfter(number3575, number275775)

        For Each Dbl As Double In Numbers
            lbxLinkedListOriginal.Items.Add(Dbl)
        Next

        Numbers.Remove(number275775)

        For Each Dbl As Double In Numbers
            lbxLinkedListOther.Items.Add(Dbl)
        Next
    End Sub

End Class

Linked List

Clearing a Linked List

Clearing a list consists of deleting all of its item. To do this, you could continuous call one of the versions of the Remove() method. A faster solution is to call the Clear() method. Its syntax is:

Public Sub Clear
 
 
   
 

Home Copyright © 2010-2016, FunctionX