-
I am doing a project for election results...
I have the candidates in an array
dim ElectionResult(30,1)
aCandidate = 0
aVotes = 1
ElectionResult(0,aCandidate) = "Gore"
ElectionResult(1,aCandidate) = "Bush"
etc
if there a fast was to sort these by the number of votes they have. Is there a better way to hold the data.
(no databases!)
thanks
-
Don't bother sorting. Just hard-code "Gore" at the top of the list :)
-
Sorry, you are talking to a New Hampshire Republican
-
There are many algorithms to perform an array sort instead of a DB sort.
The most popular and easiest to implement is the bubble sort algorithm, but this is not interesting if you are using a large set of elements.
Another algorithm is the quick sort method. This evolves some more code to implement but is very quick.
These are the most common algorithms.
To find something in an array (which has to be sorted alphabetically), you could use the binary search algorithm.
-
In the spirit of Compassionate liberalism let me point out that there are a lot of references to Sort in this forum. for example
http://forums.vb-world.net/showthrea...threadid=31965