Skip to main content

Find largest node value of doubly linked list in

Vb program for Find largest node value of doubly linked list. Here more information.

' Include namespace system
Imports System 
' program for
'  Find max value in doubly linked list

'  Define class of linked list Node
Public Class LinkNode 
    Public  data As Integer
    Public  [next] As LinkNode
    Public  prev As LinkNode
    Public Sub New(ByVal data As Integer) = data = Nothing
        Me.prev = Nothing
    End Sub

End Class
public Class DoublyLinkedList 
    Public  head As LinkNode
    Public  tail As LinkNode
    Public Sub New()
        '  Set head and tail
        Me.head = Nothing
        Me.tail = Nothing
    End Sub
    '  Insert new node at end position
    Public Sub insert(ByVal value As Integer)
        '  Create a new node
        Dim node As LinkNode = New LinkNode(value)
        if (Me.head  Is  Nothing) Then 
            '  Add first node
            Me.head = node
            Me.tail = node
        End If
        '  Add node at last position
        Me.tail.[next] = node
        node.prev = Me.tail
        Me.tail = node
    End Sub
    Public Function  maximum() As Integer
        if (Me.head  Is  Nothing) Then 
            '  When empty linked list
            Return 0
        End If

        Dim result As Integer =

        '  Get first node of linked list
        Dim temp As LinkNode = Me.head
		'  iterate linked list 
        while (temp IsNot Nothing) 
            if ( > result) Then 
                result =
            End If

            '  Visit to next node
            temp = temp.[next]
        End While
        '  Return maximum value
        Return result
    End Function 
    Public Shared Sub Main(ByVal args As String())
        Dim dll As DoublyLinkedList = New DoublyLinkedList()
        '  Insert following linked list nodes
        Console.WriteLine("Maximum  : " + dll.maximum().ToString())
    End Sub

End Class


Maximum  : 31


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment