Find largest node value of doubly linked list in vb.net
Vb program for Find largest node value of doubly linked list. Here more information.
' Include namespace system
Imports System
' Vb.net 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)
Me.data = data
Me.next = 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
Return
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 = Me.head.data
' Get first node of linked list
Dim temp As LinkNode = Me.head
' iterate linked list
while (temp IsNot Nothing)
if (temp.data > result) Then
result = temp.data
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
dll.insert(14)
dll.insert(31)
dll.insert(12)
dll.insert(15)
dll.insert(11)
dll.insert(25)
Console.WriteLine("Maximum : " + dll.maximum().ToString())
End Sub
End Class
Output
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