VB 成绩排名程序用冒泡排序

来源:百度知道 编辑:UC知道 时间:2024/09/25 02:26:42
用VB做成绩排名程序,而且用冒泡排序。
谢谢!
(情况如下:2个text,2个list,在第一个text里输名字,第二个text里输入成绩,然后回车,在第一个list里名字和成绩显示在一起,然后重新再输入新的名字+成绩……然后再单击一个command,在第二个list里显示排名好的顺序(名字和对应成绩)。)
能有解释更好了……万分感谢!
呃……这些都没学过诶……而且要用冒泡排序呃……

Dim i As Integer, N() As String, M() As String

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
i = i + 1
ReDim Preserve N(i)
ReDim Preserve M(i)
N(i) = Text1.text
M(i) = Text2.text
List1.AddItem N(i) & " " & M(i)
End If
End Sub

Private Sub Command1_Click()' 冒泡排序
Dim i As Integer, N As String, M As String
For i = List1.ListCount To 1 Step -1
For j = 1 To i
If M(j) < M(j + 1) Then
M = M(j)
N = N(j)
M(j) = M(j + 1)
N(j) = N(j + 1)
M(j + 1) = M
N(j + 1) = N
End If
Next
Next
List2.Clear
For i = 1 To List1.ListCount
List2.AddItem N(i) & " " & M(i)
Next
End Sub

Option Explicit

Private Sub Command1_Click()
Dim I As Integer, J As Integer, K As Integer
Dim N As Integer, L As Integer