2013-02-10 34 views
1

我需要一些幫助,這插入排序,我到目前爲止的代碼是這樣的:插入排序,並採取相關的陣列與它

Private Sub SortedList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    Dim currentitem As Integer = 2 
    While currentitem <= numitems 
     currentdataitem = frmEntry.starname(currentitem) 
     comparison = 1 
     finish = False 
     While comparison < currentitem And finish = False 
      If currentdataitem < frmEntry.starname(comparison) Then 
       shuffleitem = currentitem 
       While shuffleitem > comparison 
        frmEntry.starname(shuffleitem) = frmEntry.starname(shuffleitem - 1) 
        shuffleitem = shuffleitem - 1 
       End While 
       frmEntry.starname(comparison) = currentdataitem 
       finish = True 
      End If 
      comparison = comparison + 1 
     End While 
     currentitem = currentitem + 1 
    End While 
    arrayindex = 0 
    For Me.arrayindex = 1 To numitems 
     lstsorted.Items.Clear() 
     lstsorted.Items.Add(frmEntry.starname(arrayindex)) 
     lstsorted.Items.Add(frmEntry.DOB(arrayindex)) 
     lstsorted.Items.Add(frmEntry.rank(arrayindex)) 
    Next 
End Sub 

這種插入排序他們的名字,但我也需要採取他們的DOB和他們的排名,在我的視覺基本代碼中的哪個點上,我會這樣做?

回答

2

只要移動星號的元素,就可以移動DOB和秩的相應元素。

+0

我做到了,但它不起作用,它使得它們的分配相同,但最後一個是不同的。這是新的代碼,有人可以通過向我解釋/顯示我的位置來協助嗎? 雖然shuffleitem>比較 frmEntry.starname(shuffleitem)= frmEntry.starname(shuffleitem - 1) frmEntry.DOB(shuffleitem)= frmEntry.DOB(shuffleitem - 1) frmEntry.rank(shuffleitem)= frmEntry.rank( shuffleitem - 1) shuffleitem = shuffleitem - 1 End雖然 無法格式化 – 2013-02-10 09:10:51