Mega Code Archive

 
Categories / VB.Net / Data Structure
 

LinkedListNode(Of (T)), adds it to a LinkedList(Of (T)), tracks values of its properties as the LinkedList(Of (T)) changes.

Imports System Imports System.Collections.Generic Public Class GenericCollection     Public Shared Sub Main()         Dim lln As New LinkedListNode(Of String)("A")         DisplayProperties(lln)         Dim ll As New LinkedList(Of String)         ll.AddLast(lln)         DisplayProperties(lln)         ll.AddFirst("B")         ll.AddLast("C")         DisplayProperties(lln)     End Sub     Public Shared Sub DisplayProperties(lln As LinkedListNode(Of String))         If lln.List Is Nothing Then             Console.WriteLine("Node is not linked.")         Else             Console.WriteLine("Node belongs to a linked list with {0} elements.", lln.List.Count)         End If          If lln.Previous Is Nothing Then             Console.WriteLine("Previous node is null.")         Else             Console.WriteLine("Value of previous node: {0}", lln.Previous.Value)         End If          Console.WriteLine("Value of current node:  {0}", lln.Value)         If lln.Next Is Nothing Then             Console.WriteLine("Next node is null.")         Else             Console.WriteLine("Value of next node:     {0}", lln.Next.Value)         End If      End Sub  End Class