VB.NET tutorial-count elements


VB.NET OOP example

Count elements

Step 3: Count elements of the circularly linked list

To count all elements of the circularly linked list, we will need a loop to traverse through the circularly linked list. We will let a link (i) of ListElem type to point to the pfirst then move the link to its next element and increase the number of item(t) one at a time by using a while loop until the end of the circularly linked list is reached.

'count items in the Circulary Linked List
Public Overrides Function countitem() As Integer
   Dim i As ListNode
   Dim t As Integer = 0
 Try
    If (Not IsNothing(pfirst)) Then
         i = pfirst.nextlk
         t = 1
        While Not Object.Equals(i, pfirst)
            t = t + 1
            i = i.nextlk

        End While

    End If
  Catch Ex As Exception

  End Try

 Return t

End Function




Comments

CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.