VB.Net program to delete the given node from the singly linked list

Hello, VB.Net program to delete the given node from the singly linked list We are going to know the vibrancy of. There are many interesting facts in this article. Let’s move on to the articles

VB.Net program to delete the given node from the singly linked list

VB.Net program to delete the given node from the singly linked list

'VB.Net program to delete the given node from 
'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
            Else
                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

        Public Sub DeleteNode(ByVal given As ListNode)
            Dim node As ListNode
            node = Me
            While IsNothing(node) = False
                If node.link.Equals(given) Then
                    node.link = given.link
                    GoTo ExitLabel
                End If
                node = node.link
            End While
ExitLabel:
        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("Linked list before deletion:")
        StartNode.ListTraverse()

        StartNode.DeleteNode(n2)
        Console.WriteLine("Linked list after deletion:")
        StartNode.ListTraverse()
    End Sub
End Module
Linked list before deletion:
-->101
-->102
-->103
-->104
-->105
Linked list after deletion:
-->101
-->102
-->104
-->105
Press any key to continue . . .

Final Words

We hope that you and your doubts have been resolved through the article VB.Net program to delete the given node from the singly linked list. And if you have any doubts let us know via the comment box. We cater to your doubts. And if you liked this article, we ask you to share it with your friends.

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

Share on:

Leave a Comment