VB.NET tutorial-find an element of linked list


VB.NET OOP example

Find an element of linked list

Step 6: Searching for an item in the circularly linked list

Another important operation of the circularly linked list is searching for an item. To search for a specific item in the circularly linked list is a sequential process. The comparison starts from the beginning of the list until the target item is found or until the end of the list is reached. Therefore, the firs matched item is returned.

'Find an item of the List
Public Overrides Function find(ByVal val As Integer) As ListNode
  Dim tar As ListNode
  Dim f As Boolean = False

  If (Not IsNothing(pfirst)) Then
     If (pfirst.val = val) Then
         Return pfirst 'Found at the beginning of the circularly linked list
     Else
         tar = pfirst.nextlk
         While Not Object.Equals(tar, pfirst)
             If (val = tar.val) Then
                f = True
                Exit While
             End If
             tar = tar.nextlk
        End While
        If (f = True) Then

             Return tar
        Else
             Return Nothing
        End If
   End If
 Else
     Return Nothing
End If
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.