Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim A() As Integer Dim B() As Integer
Randomize() Dim k As Integer Dim i As Integer i = Rnd() * 100 + 1 ReDim A(i) For k = 0 To i A(k) = Rnd() * -1000 + 500 Next i = Rnd() * 100 + 1 ReDim B(i) For k = 0 To i B(k) = Rnd() * -1000 + 500 Next
1. Dim msg_A As String msg_A = VerifySort(A) If msg_A <> CStr(A.Length) Then MsgBox(msg_A) Else MsgBox("Массив А упорядочен") End If
Dim msg_B As String msg_B = VerifySort(B) If msg_B <> CStr(A.Length) Then MsgBox(msg_B) Else MsgBox("Массив B упорядочен") End If
sort(A) msg_A = VerifySort(A) If msg_A <> CStr(A.Length) Then MsgBox(msg_A) Else MsgBox("Массив А упорядочен") End If
2. Dim h As Integer h = InputBox("Введите h") i = CompareValue(A, h) If i <> UBound(A) Then MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.") Else MsgBox("У массива все элементы больше h.") End If
i = CompareValue(B, h) If i <> UBound(B) Then MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.") Else MsgBox("У массива все элементы больше h.") End If End Sub
Private Function VerifySort(ByRef Massiv() As Integer) As String Dim i, j, k As Integer Dim msg As String For i = Massiv.Length To 0 Step -1 For j = Massiv.Length - 1 To 1 Step -1 If Massiv(j) < Massiv(j - 1) Then For k = 0 To Massiv.Length - 1 msg = msg & Massiv(k) & vbCrLf Next Return msg End If Next j Next i Return Massiv.Length End Function Private Function sort(ByRef Massiv() As Integer) As Integer Dim i, j, Dump As Integer For i = Massiv.Length To 0 Step -1 For j = Massiv.Length - 1 To 1 Step -1 If Massiv(j) < Massiv(j - 1) Then Dump = Massiv(j) Massiv(j) = Massiv(j - 1) ' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535 Massiv(j - 1) = Dump End If Next j Next i Return Massiv.Length End Function
Private Function CompareValue(ByRef Massiv() As Integer, ByVal h As Integer) As Integer Dim count As Integer Dim i As Integer For i = 0 To UBound(Massiv) - 1 If Massiv(i) > h Then count = count + 1 ' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535 Next Return count End Function
Dim A() As Integer
Dim B() As Integer
Randomize()
Dim k As Integer
Dim i As Integer
i = Rnd() * 100 + 1
ReDim A(i)
For k = 0 To i
A(k) = Rnd() * -1000 + 500
Next
i = Rnd() * 100 + 1
ReDim B(i)
For k = 0 To i
B(k) = Rnd() * -1000 + 500
Next
1.
Dim msg_A As String
msg_A = VerifySort(A)
If msg_A <> CStr(A.Length) Then
MsgBox(msg_A)
Else
MsgBox("Массив А упорядочен")
End If
Dim msg_B As String
msg_B = VerifySort(B)
If msg_B <> CStr(A.Length) Then
MsgBox(msg_B)
Else
MsgBox("Массив B упорядочен")
End If
sort(A)
msg_A = VerifySort(A)
If msg_A <> CStr(A.Length) Then
MsgBox(msg_A)
Else
MsgBox("Массив А упорядочен")
End If
2.
Dim h As Integer
h = InputBox("Введите h")
i = CompareValue(A, h)
If i <> UBound(A) Then
MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.")
Else
MsgBox("У массива все элементы больше h.")
End If
i = CompareValue(B, h)
If i <> UBound(B) Then
MsgBox("У массива не все элементы больше h. Значений больше h " & i & " шт.")
Else
MsgBox("У массива все элементы больше h.")
End If
End Sub
Private Function VerifySort(ByRef Massiv() As Integer) As String
Dim i, j, k As Integer
Dim msg As String
For i = Massiv.Length To 0 Step -1
For j = Massiv.Length - 1 To 1 Step -1
If Massiv(j) < Massiv(j - 1) Then
For k = 0 To Massiv.Length - 1
msg = msg & Massiv(k) & vbCrLf
Next
Return msg
End If
Next j
Next i
Return Massiv.Length
End Function
Private Function sort(ByRef Massiv() As Integer) As Integer
Dim i, j, Dump As Integer
For i = Massiv.Length To 0 Step -1
For j = Massiv.Length - 1 To 1 Step -1
If Massiv(j) < Massiv(j - 1) Then
Dump = Massiv(j)
Massiv(j) = Massiv(j - 1)
' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
Massiv(j - 1) = Dump
End If
Next j
Next i
Return Massiv.Length
End Function
Private Function CompareValue(ByRef Massiv() As Integer, ByVal h As Integer) As Integer
Dim count As Integer
Dim i As Integer
For i = 0 To UBound(Massiv) - 1
If Massiv(i) > h Then count = count + 1
' c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
Next
Return count
End Function