在排序之前将文件详细信息读入数组

时间:2015-12-27 17:23:40

标签: arrays vb.net

我目前正在研究游泳者的数据库系统,使用文本文件将数据和ASA号码存储为主键。我想将这些细节读入数组,以便我可以更轻松地快速分配它们。但是,我卡在阵列和快速排序上,我不知道如何继续。下面是我到目前为止的代码。

对于数组:

Sub ReadSwimmerFile()
    Dim Count As Integer
    Dim Swimmer() As aSwimmer

    'Finds the number of records in 'swimmers.txt'
    Dim SwimmerFile As String() = IO.File.ReadAllLines("Swimmers.txt")
    Dim Last As Integer = Len(SwimmerFile)

    'reads out records in 'Swimmer.txt' into an array
    FileOpen(1, "Swimmer.txt", OpenMode.Input)
    While Not EOF(1)
        For Count = 0 To Last
            Input(1, Swimmer(Count).ASANo)
            Input(1, Swimmer(Count).Surname)
            Input(1, Swimmer(Count).Name)
            Input(1, Swimmer(Count).DoB)
            Input(1, Swimmer(Count).Gender)
            Input(1, Swimmer(Count).MembType)
            Input(1, Swimmer(Count).Squad)
            Input(1, Swimmer(Count).Address1)
            Input(1, Swimmer(Count).Address2)
            Input(1, Swimmer(Count).Address3)
            Input(1, Swimmer(Count).Town)
            Input(1, Swimmer(Count).County)
            Input(1, Swimmer(Count).Postcode)
            Input(1, Swimmer(Count).HomeNo)
            Input(1, Swimmer(Count).MobileNo)
            Input(1, Swimmer(Count).Email)
            Input(1, Swimmer(Count).DateJoint)
        Next
    End While
    FileClose(1)

End Sub

快速排序:

    Dim J As Integer
    Dim K As Integer
    If First < Last Then
        J = First
        K = Last + 1
        Do
            Do
                J = J + 1
            Loop Until ASANo(J) >= ASANo(First) Or J = Last

            Do
                K = K - 1
            Loop Until ASANo(K) <= ASANo(First)

            If J < K Then
                Call Swap(ASANo(J), ASANo(K))
            End If

        Loop Until J >= K

        Call Swap(ASANo(First), ASANo(K))
        Call QuickSort(First, K - 1, ASANo)
        Call QuickSort(K + 1, Last, ASANo)
    End If
End Sub

任何人都可以告诉我从哪里开始,或者即使我的代码效率低下,并建议采用不同的方法来解决这个问题吗?

0 个答案:

没有答案