Introduction to Computer Science Recursive Array Programming Recursive Sorting Algorithms Unit 16.
CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays...
-
Upload
hester-baker -
Category
Documents
-
view
215 -
download
0
Transcript of CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays...
![Page 1: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/1.jpg)
CSC 162
Visual Basic I Programming
![Page 2: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/2.jpg)
Array Parameters and Sorting• Array Parameters
– Entire Arrays– Individual Elements
• Sorting– Bubble Sort
![Page 3: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/3.jpg)
Array Parameters
• When arrays are passed to procedures, they must be passed ByRef.– Visual Basic makes this a requirement since copying
large arrays could take up too much room in memory.
![Page 4: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/4.jpg)
Array Parameters
• Array parameters are not specified with a size, since they are passed ByRef.
Private Sub PrintNums(ByRef intNums() As Integer)
Dim intCounter As Integer
For intCounter = LBound(intNums) To UBound(intNums)
Print intNums(intCounter)
Next intCounter
End Sub
![Page 5: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/5.jpg)
Array Parameters
• When arrays are passed into a procedure, the size is also not specified, since they are passed ByRef.
Dim intValues(1 To 100) As Integer
.
.
.
Call PrintNums(intValues())
![Page 6: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/6.jpg)
Array Parameters• However, individual elements of the array are passed just
like any single value.
Private Sub PrintValue(ByVal intValue As Integer)
Print "The selected value is " & intValue
End Sub
Dim intNumbers(1 To 50) As Integer
.
.
.
Call PrintValue(intNumbers(20))
![Page 7: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/7.jpg)
Bubble Sort• Arrays can be sorted in two ways:
– Ascending (1 100, A Z, etc.)
– Descending (100 1, Z A, etc.)
• Array functions:– Starting index (lower bound):LBound()– Ending index (upper bound): UBound()
![Page 8: CSC 162 Visual Basic I Programming. Array Parameters and Sorting Array Parameters –Entire Arrays –Individual Elements Sorting –Bubble Sort.](https://reader036.fdocuments.in/reader036/viewer/2022082612/56649f1e5503460f94c362ed/html5/thumbnails/8.jpg)
Lab AssignmentWrite a program that will do the following: 1. Put 20 random (integer) numbers with a range of 1 to 100
into an array of size 20. 2. Sort the array in descending order.*3. Display the entire sorted array in a ListBox.
* Use the Bubble Sort algorithm, but put it into a sub procedure called DescendingSort.
Programming Assignment 5Due Monday, November 10 / Tuesday, November 11Page 241 #6.18Page 241 #6.19