|
-
Jul 14th, 2003, 06:08 PM
#12
Lively Member
Here is a simple algorithm if you want the 3 greatest values from an Array. Sorry vb isn't my language of choice but this pseudocode should get the point across.
int top3 [3] // Array of 3
int yournumbers[50] // Array of 50
int i
int j = 0
while j < 3 // Loop for the number of Maxs
i = 0
while (i < yournumber.length) // Loop for the number in the array
if (yournumber[i] > top3[j]) then
top3[j] = yournumbers[i]
yournumbers[i] = 0 // Make sure it won't reappear
end if
i++ // increment i
end while
j++
end while
This code assumes an integer array initalises its values to 0. It will run with a complexity of N * M where N is the yournumbers array and M is the number of maxs your looking for.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|