Posted on by Kalkicode
Code Doubly linked list

Find the smallest number in the doubly linked list in

Vb program for Find the smallest number in the doubly linked list. Here problem description and explanation.

' Include namespace system
Imports System 
' program for
'  Find the smallest node in doubly linked list

'  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 inital value
        Me.head = Nothing
        Me.tail = Nothing
    End Sub
    '  Insert new node at end position
    Public Sub insert(ByVal value As Integer)
        '  Create a 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
        '  new last node
        Me.tail = node
    End Sub
    '  Find smallest number
    Public Sub minNumber()
        if (Me.head  Is  Nothing) Then
            Console.WriteLine("Empty Linked List")
            '  Get first node of linked list
            Dim temp As LinkNode = Me.head
            Dim result As Integer =
            '  iterate linked list
            while (temp IsNot Nothing)
                if ( < result) Then
                    '  Get new minimum
                    result =
                End If
                '  Visit to next node
                temp = temp.[next]
            End While
            Console.WriteLine("Smallest : " + result.ToString())
        End IF
    End Sub
    Public Shared Sub Main(ByVal args As String())
        Dim dll As DoublyLinkedList = New DoublyLinkedList()
        '  Insert following linked list nodes
    End Sub
End Class


Smallest : 11


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