private void CalculateAgeDifferences(List <AgeComparison> ageDifferences) { for (var i = 0; i < _people.Count - 1; i++) { for (var j = i + 1; j < _people.Count; j++) { var ageComparison = new AgeComparison( _people[i], _people[j]); ageDifferences.Add(ageComparison); } } }
private void AssignOldestYoungest(int i, int j, AgeComparison ageComparison) { if (_people[i].BirthDate < _people[j].BirthDate) { ageComparison.Oldest = _people[i]; ageComparison.Youngest = _people[j]; } else { ageComparison.Oldest = _people[j]; ageComparison.Youngest = _people[i]; } }
private void SortPeopleByBirthDate() { for (var i = 0; i < _people.Count - 1; i++) { for (var j = i + 1; j < _people.Count; j++) { var comparison = new AgeComparison(); _ageComparisonList.Add(comparison); AssignOldestYoungest(i, j, comparison); SetAgeDifference(); } } }
protected override AgeComparison FindAnswer( List <AgeComparison> ageDifferences) { if (ageDifferences.Count < 1) { return(new AgeComparison()); } AgeComparison answer = ageDifferences[0]; foreach (var result in ageDifferences) { if (result.AgeDifference < answer.AgeDifference) { answer = result; } } return(answer); }