编写VB程序,实现上述功能。运行程序,在列表框List1中显示全部图书编号。单击“整理”按钮Command1,在标签Label1中显示待调整区间图书的册数,在文本框Text1中显示待调整区间图书的起止编号,并在列表框List2中显示排序后的图书编号。程序运行界面如图所示,其中①和②两处分别指向待调整区间图书的起始和截止编号。
'n是常量,代码略
Dim a(0 To n) As String
Private Sub Form_ Load()
a(0)= "”
'将n册图书的编号存入数组元素a(1)~a(n),在List1中显示,代码略
End Sub
Private Sub Command1_ Click()
Dim i As Integer, k As Integer, left As Integer, right As Integer
Dim min As String, max As String
min= ": max= ": left= 1: right= 0
For i= 1 To n- 1
If a(i)> a(i + 1) Then
max = a(i)
left= i: Exit For
End If
Next i
For i=n To 2 Step-1
If Then
min= a(i)
right= i: Exit For
End If
Next i
i= left
Do While i <= right
If a(i)> max Then
max = a(i)
ElseIf a(i) < min Then
min= a(i)
End If
i=i+ 1
Loop
k=0
If left < right Then
left = getPos(1, left, min)
k= right- left+ 1
Text1.Text= "待调整区间图书起始编号: " + a(left) + "-->截止编号: "+ a(right)
End If
Label1.Caption = "待调整区间图书共有:" + Str(k) + "册"
'对待调整区间的图书编号进行排序,在List2中输出整理结果,代码略
End Sub
Function getPos(head As Integer, tail As Integer, value As String) As Integer
Dim i As Integer
i= tai1
Do While
i=i- 1
Loop
getPos=i+ 1
End Function