编写VB程序,实现上述合并功能。运行程序时,将n堆果子的重量从数据库读入到a数组。单击“合并”按钮Command1后,在文本框Text1中输出最小的体力耗费值。请回答下列问题:
Private Sub Form_ Load( )
‘将n堆果子的重量从数据库导入到数组a,代码略。
End Sub
Private Sub Command1_Click( )
Dim f As Boolean
Dim last As Integer
Dim a(1 To n) As Integer
i= 1
Do While i<n And Not f
f=True
For j=n To i+1 Step-1
If a(j)<a(j- 1) Then
t= a(j): a(j)=a(j- 1): a(j-1)=t
last= j
f= False
End If
Next j
Loop
For i= 1 To n-2
tmp=a(i)+a(i+1)
j=
Do While a(j)< tmp
a(j-1)= a(j)
j=j+1
If j=n+ 1 Then Exit Do
Loop
Min=Min+tmp
Next i
Text1.Text = Min
End Sub