VB.net Program to Traverse the Singly Linked List

You are currently viewing VB.net Program to Traverse the Singly Linked List

VB.Net program to traverse the singly linked list

'VB.Net program to traverse the singly linked list.

Imports System

Module Module1
    Class ListNode
        Private item As Integer
        Private link As ListNode

        Public Sub New(ByVal value As Integer)
            item = value
            link = Nothing
        End Sub
        Public Function AddItem(ByVal value As Integer) As ListNode
            Dim node As New ListNode(value)
            If IsNothing(link) Then
                node.link = Nothing
                link = node
                Dim temp As ListNode
                temp = link
                node.link = temp
                link = node
            End If
            Return node
        End Function

        Public Sub ListTraverse()
            Dim node As ListNode
            node = Me
            While IsNothing(node) = False
                Console.WriteLine("-->" & node.item)
                node = node.link
            End While
        End Sub
    End Class

    Sub Main()
        Dim StartNode As New ListNode(101)

        Dim n1 As ListNode
        Dim n2 As ListNode
        Dim n3 As ListNode
        Dim n4 As ListNode

        n1 = StartNode.AddItem(102)
        n2 = n1.AddItem(103)
        n3 = n2.AddItem(104)
        n4 = n3.AddItem(105)

        Console.WriteLine("Traversing of Linked list:")
    End Sub
End Module
Traversing of Linked list:
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply