Wagner et Fisher : VB.net

Private Function WagnerAndFisher(ByRef tabMots As String(), ByVal mot As String) As ArrayList
    Dim tailleTab As Integer = tabMots.Length
    Dim longMot As Integer = mot.Length
    Dim longueur As Integer() = New Integer(tailleTab - 1) {}
    Dim temp As String
    Dim modif As Boolean = False
 
    Do
        modif = False
 
        For i As Integer = 1 To tabMots.Length - 1
 
            If tabMots(i).Length > tabMots(i - 1).Length Then
                modif = True
                temp = tabMots(i)
                tabMots(i) = tabMots(i - 1)
                tabMots(i - 1) = temp
            End If
        Next
    Loop While modif
 
    For cptMots As Integer = 0 To tailleTab - 1
        Dim longMotTest As Integer = tabMots(cptMots).Length
        Dim tab_char As Char() = New Char(longMotTest - 1) {}
        tab_char = tabMots(cptMots).ToUpper().ToCharArray()
        Dim matrice As Integer(,) = New Integer(longMotTest - 1, longMot - 1) {}
        matrice(0, 0) = 0
        Dim m1 As Integer
        Dim m2 As Integer
        Dim m3 As Integer
 
        For i As Integer = 1 To longMotTest - 1
            matrice(i, 0) = matrice(i - 1, 0) + 1
        Next
 
        For j As Integer = 1 To longMot - 1
            matrice(0, j) = matrice(0, j - 1) + 1
        Next
 
        For i As Integer = 1 To longMotTest - 1
 
            For j As Integer = 1 To longMot - 1
 
                If tab_char(i) = mot(j) Then
                    m1 = matrice(i - 1, j - 1)
                Else
                    m1 = matrice(i - 1, j - 1) + 1
                End If
 
                m2 = matrice(i - 1, j) + 1
                m3 = matrice(i, j - 1) + 1
 
                If (m1 <= m2) AndAlso (m1 <= m3) Then
                    matrice(i, j) = m1
                ElseIf (m2 <= m1) AndAlso (m2 <= m3) Then
                    matrice(i, j) = m2
                ElseIf (m3 <= m2) AndAlso (m3 <= m1) Then
                    matrice(i, j) = m3
                End If
            Next
        Next
 
        longueur(cptMots) = matrice(longMotTest - 1, longMot - 1) + cptMots
    Next
 
    Dim min As Integer = longueur(0)
    Dim resultat As String() = New String(tailleTab - 1) {}
    Dim cpt As Integer = 0
 
    For i As Integer = 0 To tailleTab - 1
 
        If min > longueur(i) Then
            min = longueur(i)
            resultat(0) = tabMots(i)
            cpt = 1
        ElseIf min = longueur(i) Then
            resultat(cpt) = tabMots(i)
            cpt = cpt + 1
        End If
    Next
 
    Dim listeRetour As ArrayList = New ArrayList()
 
    For i As Integer = 0 To resultat.Length - 1
        listeRetour.Add(resultat(i))
    Next
 
    listeRetour.Sort()
    Return listeRetour
End Function

source : https://www.developpez.net/forums/d523279/general-developpement/algorithme-mathematiques/contribuez/wagner-fisher-csharp/