a(1) |
a(2) |
a(3) |
…… |
a(n-2) |
a(n-1) |
a(n) |
99 |
77 |
55 |
…… |
44 |
66 |
88 |
根据上述排序特点,小达编写了一个VB程序,其功能如下:在文本框Text1中输入n个正整数(以“,”为分割符),单击“排序”按钮Command1进行排序,在文本框Text2中显示左右交替下降的数据,程序运行界面如图所示。
实现上述功能的VB程序如下,请回答下列问题:
Private Sub Command1_Click( )
Dim a(1 To 100) As Integer
Dim s As String, ch As String, k As Integer, t As Integer
Dim n As Integer, i As Integer, j As Integer, s1 As Integer
s= Text1. Text : n=0 : s1=0
For i=1 To Len(s)
ch= Mid(s,i,1)
If ch>= "O" And ch <= "9" Then
s1 =
Else
n=n+1: a(n)=s1: s1=0
End If
Next i
For i=1 To n-1
If i Mod 2=1 Then
k=i \2+1
Else
k=
End If
pos= k
For j=i\ 2 + 1 To n- (i- 1)\ 2
If a(j) > a( pos) Then
Next j
If k <> pos Then t= a(k) : a(k) =a(pos) : a(pos)=t
Next i
For i=1 To n
Text2. Text= Text2. Text+Str(a(i))
Next i
End Sub