Function Hash(Key) As Integer
Dim Address As Integer
Dim x, y, num1, num2, num3, num4, total As Integer
Dim a, b As Char
Dim c As String
x = Asc(a)
b = Mid(Key, 2, 1)
y = Asc(b)
c = Right(Key, 4)
num1 = CInt(Left(c, 1))
num2 = CInt(Mid(c, 2, 1))
num3 = CInt(Mid(c, 3, 1))
num4 = CInt(Right(c, 1))
total = x + y + num1 + num2 + num3 + num4
Address = total Mod 6
Return Address
Dim HashTable(5) As String
Sub Main()
Dim Key As String
Dim Index As Integer
Dim Max = 5
For i = 1 To 5
Console.WriteLine("Enter CustomerID.")
Key = Console.ReadLine
Index = Hash(Key)
While HashTable(Index) <> Nothing
Index = Index + 1
If Index > Max Then
Index = 1
End If
End While
HashTable(Index) = Key
Next
For i = 1 To 5
Console.WriteLine(HashTable(i))
Next
End Sub
Function SearchHashTable(SearchID) As Integer
Index = Hash(SearchID)
While HashTable(Index) <> SearchID And HashTable(Index) = Nothing
Index = Index + 1
If Index > 5 Then
Index = 0
End If
End While
If HashTable(Index) = SearchID Then
Console.WriteLine("ID Found.")
Return Index
Else
Console.WriteLine("ID not found.")
Return -1
End If
End Function
Function OutputLetter(B) As Integer
If x = Len(B) Then
End
Else
x = x + 1
Console.WriteLine(Mid(B, x, 1))
OutputLetter(B)
End If
Return x
End Function
uj5u.com熱心網友回復:
這就是一個hash表搜索的代碼,你先自己轉個大概,一兩行不會可以幫你轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/11967.html
標籤:VB基礎類
