private static void ApplyEnrollees(Stack <Enrollee> enrollees, Dictionary <uint, Specialty> specialties) { while (enrollees.Any()) { var enrollee = enrollees.Pop(); enrollee.AppliedIndex++; if (enrollee.AppliedIndex < 0) { enrollee.AppliedIndex = 0; } if (enrollee.AppliedIndex < enrollee.Choices.Count) { var specialty = specialties [enrollee.Choices.ElementAt(enrollee.AppliedIndex).Value]; int index; for (index = 0; index < specialty.Enrollees.Count; index++) { if (CompareEnrollees.IsFirstEnrolleeBetter(specialty, enrollee, specialty.Enrollees [index])) { specialty.Enrollees.Insert(index, enrollee); break; } } if (index >= specialty.Enrollees.Count) { specialty.Enrollees.Add(enrollee); } } } }
private static void CheckCorrectness(Dictionary <uint, Enrollee> enrollees, Dictionary <uint, Specialty> specialties) { foreach (var enrolleeData in enrollees) { var enrollee = enrolleeData.Value; if (enrollee.AppliedIndex >= enrollee.Choices.Count) { foreach (var choiceData in enrollee.Choices) { var specialty = specialties [choiceData.Value]; foreach (var anotherEnrollee in specialty.Enrollees) { if (CompareEnrollees.IsFirstEnrolleeBetter(specialty, enrollee, anotherEnrollee)) { throw new Exception("Enrollee " + enrolleeData.Key + "is better than one of the" + "enrollees of " + choiceData.Value + ", but it wasn't applied!"); } } } } } }