# Sum of smaller elements of nodes in a linked list in vb.net

Vb program for Sum of smaller elements of nodes in a linked list. Here problem description and other solutions.

``````' Include namespace system
Imports System
' Vb.net program for
' Sum of smallest element of linked list

Public  a As Integer
Public  b As Integer
Public Sub New(ByVal a As Integer,
ByVal b As Integer)
Me.a = a
Me.b = b
Me.next = Nothing
End Sub
End Class
public Class SingleLL
Public Sub New()
Me.tail = Nothing
End Sub
Public Sub insert(ByVal a As Integer,
ByVal b As Integer)
Else
'  Add node at the end position
Me.tail.[next] = node
End IF
'  new last node
Me.tail = node
End Sub
Public Sub display()
Return
End If
while (temp IsNot Nothing)
Console.Write(" (" + temp.a.ToString() +
"," + temp.b.ToString() + ") →")
'  Visit to next node
temp = temp.[next]
End While
Console.WriteLine(" NULL")
End Sub
'  Find the sum of smaller elements of
'  every node in a linked list
Public Function  nodeSum() As Integer
Dim result As Integer = 0
if (temp  Is  Nothing) Then
Else
'  And
'  Sum of smallest key in every node of linked list
while (temp IsNot Nothing)
if (temp.a > temp.b) Then
'  When key b is small
result += temp.b
Else
'  When key a is small
result += temp.a
End IF
'  Visit to next node
temp = temp.[next]
End While
End IF
Return  result
End Function
Public Shared Sub Main(ByVal args As String())
Dim sll As SingleLL = New SingleLL()
'  (3,9) → (11,4) → (3,3) → (6,1) → (2,9) → (4,7) → NULL
sll.insert(3, 9)
sll.insert(11, 4)
sll.insert(3, 3)
sll.insert(6, 1)
sll.insert(2, 9)
sll.insert(4, 7)
sll.display()
Console.WriteLine(" Result : " + sll.nodeSum().ToString())
End Sub
End Class

``````

Output

`````` Linked List
(3,9) → (11,4) → (3,3) → (6,1) → (2,9) → (4,7) → NULL
Result : 17``````

## Comment

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.