public void ShowBest(int number = 3) { if (number <= students.Count && number > 0) { List <Student> st_copy = new List <Student>(students); var tmp = new SortAverage(); tmp.Sort(st_copy); Console.WriteLine($"Best {number} students:"); for (int i = 0; i < st_copy.Count && i < number; i++) { st_copy[i].Info(); } } else { Console.WriteLine("Invalid index."); } }
static void Task2() { Group group = new Group("33СПА-2"); group.AddSt(new Student("name_one", "surn_one", "patr_one")); group.AddSt(new Student("name_two", "surn_two", "patr_two")); group.AddSt(new Student("name_three", "surn_three", "patr_three")); group.AddSt(new Student("name_four", "surn_four", "patr_four")); group.AddSt(new Student("name_five", "surn_five", "patr_five")); group.AddSt(new Student("name_six", "surn_six", "patr_six")); //group.SetRandMarks(); group.Show(); Console.WriteLine("remove student six==============================="); group.RemSt("surnsix"); group.Show(); Console.WriteLine("Sort by surname==============================="); ISortSt strategy = new SortSurname(); group.SetStrategy(strategy); group.SortGr(); group.Show(); Console.WriteLine("Sort by average==============================="); strategy = new SortAverage(); group.SetStrategy(strategy); group.SortGr(); group.Show(); Console.WriteLine("Sort by recbook==============================="); strategy = new SortRecBook(); group.SetStrategy(strategy); group.SortGr(); group.Show(); group.ShowBest(); }