my code works well in indexing all votes in the preferences except for the first one, I tried debugging and it worked well for all indexes including the first one..!
1 Answer
From the spec:
The array
preferences[i]
will represent all of the preferences for voter numberi
, and the integerpreferences[i][j]
here will store the index of the candidate who is thej
th preference for voter `i.
So j
represents the preference (rank).
In this program the i
th index (which is analagous to the j
the index from the spec) represents the candidate index.
Try/debug an election with 3 candidates (a, b, c) and 3 voters who cast the following ballots:
- c b a
- c a b
- c a b