linked list

Lets create a Linked List in, its a very common question asked in interviews. 

Mostly we use built-in List object to Add/Remove Entries from a List. what we have to create our own list....below is sample code.

Public Class Node
    Public Property Data As Object
    Public Property nextnode As Node
End Class

Public Class LinkedList

    Private head As Node

    Public Sub AddNode(ByVal n As Node)
        n.nextnode = Me.head ' NULL/NOTHING at start, then it keeps value of previous object
        Me.head = n ' Set it to Current Object
    End Sub

    Public Sub pintall()
        While (Not head Is Nothing)
            head = head.nextnode
        End While
    End Sub

End Class

And then consume it...

        Dim n As New LinkedList

        Dim n1 As New Node
        n1.Data = "Adil"

        Dim n2 As New Node
        n2.Data = "Khan"

        Dim n3 As New Node
        n3.Data = "ASP"

Posted by:

No comments posted.

Name :  

Email :  

Comment Below