The output: For the question, it said about function of SwafIf, this is my funct
ID: 3675104 • Letter: T
Question
The output:
For the question, it said about function of SwafIf, this is my function on question 1
Question 2 *Recall that bubble sort used a sequences of passes where on each pass the current largest element was moved to the right *Consider a modification to this algorithm where on each pass The current largest element is moved to the right, then The current smallest element is moved to the left *The first pass operates over indices iStart 0 to iEnd = cData - 1 *The second pass operates over indices iStart = 1 to iEnd = cData - 2 *Each subsequent pass decreases the size of the interval *The algorithm stops when the size of the interval is O ECE 114 Lab 9- Pointers 4
Explanation / Answer
Here the example it may help you to solve the issue.
Example 1
Option Explicit
Private maintRandomNumbers(1 To 5) As Integer
-------------------------------------
-----------------------------------
Example 2
Dim lngX As Long
Dim lngY As Long
Dim intTemp As Integer
For lngX = LBound(paintArray) To (UBound(paintArray) - 1)
For lngY = LBound(paintArray) To (UBound(paintArray) - 1)
If paintArray(lngY) > paintArray(lngY + 1) Then
' exchange the items
intTemp = paintArray(lngY)
paintArray(lngY) = paintArray(lngY + 1)
paintArray(lngY + 1) = intTemp
End If
Next
Next
Loop
End Sub
------------------------------------------------------------------------
Private Sub cmdGet_Click()
'------------------------------------------------------------------------
Dim intX As Integer
Cls
Randomize
For intX = 1 To 5
maintRandomNumbers(intX) = GetRandomNumber(100, 999)
Print maintRandomNumbers(intX)
Next
End Sub
'------------------------------------------------------------------------
Private Sub cmdSort_Click()
'------------------------------------------------------------------------
Dim intX As Integer
Print "The numbers sorted are:"
SortIntegerArray maintRandomNumbers
For intX = 1 To 5
Print maintRandomNumbers(intX)
Next
End Sub
'------------------------------------------------------------------------
Private Sub cmdExit_Click()
'------------------------------------------------------------------------
End
End Sub
'------------------------------------------------------------------------
Private Function GetRandomNumber(pintLowerBound As Integer, _
pintUpperBound As Integer) _
As Integer
'------------------------------------------------------------------------
' This function will return a random integer that falls with the range
' of the two arguments passed.
GetRandomNumber = Int((pintUpperBound - pintLowerBound + 1) * Rnd + pintLowerBound)
End Function
'------------------------------------------------------------------------
Private Sub SortIntegerArray(paintArray() As Integer)
'------------------------------------------------------------------------
' This sub uses the Bubble Sort algorithm to sort an array of integers.
Dim lngY As Long
Dim intTemp As Integer
Dim blnExchangeMade As Boolean
blnExchangeMade = True
Do While blnExchangeMade
blnExchangeMade = False
For lngY = LBound(paintArray) To (UBound(paintArray) - 1)
If paintArray(lngY) > paintArray(lngY + 1) Then
' exchange the items
intTemp = paintArray(lngY)
paintArray(lngY) = paintArray(lngY + 1)
paintArray(lngY + 1) = intTemp
blnExchangeMade = True
End If
Next
Loop
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.