You'll need a bubblesort (there are other ways, which may be quicker) if you need an algorithm.
Alternatively, take advantageof built in sort functions, for example the array.sort command: here's a recent link to a thread which involves sorting an array of structures, but it'll work the same way:
Dim curSmallest As Double = Double.MaxValue ' look at each number ' if the number i am looking at right now is smaller than smallest ' curSmallest is number i am looking at right now ' curSmallest is the smallest
Yeah, your second inclination is correct. Let me clean up my algorithm a bit:
Dim curSmallest As Double = Double.MaxValue ' look at each number ' if the number i am looking at right now is less than curSmallest ' curSmallest is number i am looking at right now ' curSmallest is the answer
Dim curSmallest As Double = Double.MaxValue ' look at each number ' if the number i am looking at right now is smaller than smallest ' curSmallest is number i am looking at right now ' curSmallest is the smallest
Thanks, but I am a little lost at this line...
' if the number i am looking at right now is smaller than smallest
I am not sure what to put for smallest.
if curNum < smallest then curNum = curSmallest
My guess would be that smallest above should be curSmallest, but I want to make sure.
Lots of response, here's a bit of code from QuickBasic that does the job. 'demo code to find minimum values stored in an array DIM a(1 TO 10) AS SINGLE 'a( ) contains the values DIM min, j AS SINGLE min = 1000000! 'set min to be larger than expected value a(5) = -5 'test value =-5 FOR j = 1 TO 10 IF a(j) < min THEN min = a(j) NEXT j PRINT min
Find the smallest of a group of numbers
manick312938
You'll need a bubblesort (there are other ways, which may be quicker) if you need an algorithm.
Alternatively, take advantageof built in sort functions, for example the array.sort command: here's a recent link to a thread which involves sorting an array of structures, but it'll work the same way:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1176363&SiteID=1
Be aware that this is just one way of doing it, there may be a better way: I think the link above demonstrates the most versatile way of sorting.
John Papa
Will Merydith
Dim curSmallest As Double = Double.MaxValue
' look at each number
' if the number i am looking at right now is smaller than smallest
' curSmallest is number i am looking at right now
' curSmallest is the smallest
NoEgo
Dim curSmallest As Double = Double.MaxValue
' look at each number
' if the number i am looking at right now is less than curSmallest
' curSmallest is number i am looking at right now
' curSmallest is the answer
Aaron Oneal
Thanks, but I am a little lost at this line...
I am not sure what to put for smallest.
if curNum < smallest then
curNum = curSmallest
My guess would be that smallest above should be curSmallest, but I want to make sure.
if curNum < curSmallest then
curNum = curSmallest
robhendershot
Doh!
K. Rose
'demo code to find minimum values stored in an array
DIM a(1 TO 10) AS SINGLE 'a( ) contains the values
DIM min, j AS SINGLE
min = 1000000! 'set min to be larger than expected value
a(5) = -5 'test value =-5
FOR j = 1 TO 10
IF a(j) < min THEN min = a(j)
NEXT j
PRINT min