Lecture-25(arrays-bubble)

Lecture-25(arrays-bubble) - Data Arrays Bubble Sort Example...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Arrays
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bubble Sort Example The basic idea is that one goes down an array comparing adjacent pairs and swapping values if they are out of order. We pass through the array many times until there are no more swaps. Can you write a code to implement the bubble sort logic?
Background image of page 2
Code Implementation
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Results
Background image of page 4
Dynamic Allocation In the previous, the array is specified to be of fixed size VBA also permits dynamic arrays The actual size of the array can be changed in different parts of the code using the ReDim command Supposing you have the code: Dim T(10) as Double Dim T() as Double ReDim T(5) as Double Sub calc() Dim a() as Double ReDim a(3) as Double a(0) = 2; a(1) = -1; a(2) = 2 ReDim a(5) as Double MsgBox a(2) End Sub() Every time the array is resized, the values assigned to the array are lost The value of a(2) returned is 0
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ReDim In the previous code if we need to save the old values of a, then add Preserve to the ReDim syntax ReDim can be used many times in a code. However, the data type
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Lecture-25(arrays-bubble) - Data Arrays Bubble Sort Example...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online