public static VotesCentralization[] AddToArray(ref VotesCentralization[] array, VotesCentralization newValue) { array = ResizeArray(array, 1); array[array.Length - 1] = newValue; return array; }
public static VotesCentralization[] CentralizationOrderedTotalVotes(CandidateCentralization[] candidates) { var totalOrderedVotes = new VotesCentralization[0]; for (var i = 0; i < candidates.Length; i++) { for (var k = 0; k < candidates[i].Station.Length; k++) SearchCandidate(ref totalOrderedVotes, candidates[i].Station[k].CandidateName, candidates[i].Station[k].Votes); } GetOrderlyCandidatesByNumberOfVotes(totalOrderedVotes); return totalOrderedVotes; }
public static void Swap(ref VotesCentralization x, ref VotesCentralization y) { var temp = y; y = x; x = temp; }
public static VotesCentralization[] SearchCandidate(ref VotesCentralization[] candidate, string candidateName, long votes) { var newValue = new VotesCentralization { CandidateName = candidateName, TotalVotes = votes }; for (var k = 0; k < candidate.Length; k++) { if (string.CompareOrdinal(candidateName, candidate[k].CandidateName) == 0) { candidate[k].TotalVotes += votes; return candidate; } } AddToArray(ref candidate, newValue); return candidate; }
public static VotesCentralization[] ResizeArray(VotesCentralization[] oldArray, int difference) { var newArray = new VotesCentralization[oldArray.Length + difference]; for (var i = 0; i < oldArray.Length; i++) newArray[i] = oldArray[i]; return newArray; }
public static void GetOrderlyCandidatesByNumberOfVotes(VotesCentralization[] candidate) { for (var i = 0; i < candidate.Length; i++) for (var k = i; k > 0; k--) { if (candidate[k].TotalVotes > candidate[k - 1].TotalVotes) { Swap(ref candidate[k], ref candidate[k - 1]); } } }