2013-02-10 106 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