예제 #1
0
 private AgeDifference GetNormalizedAgeDifference(int i, int j)
 {
     var normalizedAgeDifference = new AgeDifference();
     if (_persons[i].BirthDate < _persons[j].BirthDate) {
         normalizedAgeDifference.Person1 = _persons[i];
         normalizedAgeDifference.Person2 = _persons[j];
     } else {
         normalizedAgeDifference.Person1 = _persons[j];
         normalizedAgeDifference.Person2 = _persons[i];
     }
     normalizedAgeDifference.Difference = normalizedAgeDifference.Person2.BirthDate - normalizedAgeDifference.Person1.BirthDate;
     return normalizedAgeDifference;
 }
예제 #2
0
        public AgeDifference Find(FindType findType)
        {
            var AgeDifferenceList = GetAgeDifferenceList();

            AgeDifference ageDifferenceResult = new AgeDifference();

            if (AgeDifferenceList.Count > 0) {
                if (findType == FindType.MaximumDiff) {
                    AgeDifferenceList.Reverse();
                } else {
                    AgeDifferenceList.Sort();
                }
                ageDifferenceResult = AgeDifferenceList[0];
            }

            return ageDifferenceResult;
        }
예제 #3
0
        public PairOfPeople Find(AgeDifference ageDifference)
        {
            PairOfPeople output = new PairOfPeople();

            if (_allPeople.Count > 1)
            {
                var sortedPeople = SortPeopleByBirthDate();

                var possibleOutput = new PairOfPeople[2]
                {
                    GetSmallestAgeDifference(sortedPeople),
                    GetLargestAgeDifference(sortedPeople)
                };

                output = possibleOutput[(int)ageDifference];
            }

            return(output);
        }