public void Add(Student student) { studentsList.AddFirst(student); }
public Student GetElement(int index) { Student[] studentsListTab = new Student[studentsList.Count]; studentsList.CopyTo(studentsListTab, 0); return(studentsListTab[index - 1]); }
public void Sort(int sortDirection, int sortField) { int count = studentsList.Count; Student[] studentsListTab = new Student[count]; studentsList.CopyTo(studentsListTab, 0); Student[] studentsListFinish = new Student[count]; if (sortField == 1) { if (studentsList.Count > 0) { string lastWord = studentsListTab[0].FirstName; int indexLastElement = 0; for (int j = count - 1; j >= 0; j--) { for (int i = 1; i < count - 1; i++) { int compare = 0; compare = String.Compare(lastWord, studentsListTab[i].FirstName); if (compare > 0) { lastWord = studentsListTab[i].FirstName; indexLastElement = i; } } string firstName = " "; string lastName = " "; string studentNumber = " "; float averageScore = 0; firstName = studentsListTab[indexLastElement].FirstName; lastName = studentsListTab[indexLastElement].LastName; studentNumber = studentsListTab[indexLastElement].StudentNumber; averageScore = studentsListTab[indexLastElement].AverageScore; Student studentCopy = new Student(firstName, lastName, studentNumber, averageScore); Student removeByIndex = studentsListTab[indexLastElement]; studentsList.Remove(removeByIndex); studentsListFinish[j] = studentCopy; } } if (sortDirection == 1) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddLast(student); } } if (sortDirection == 0) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddFirst(student); } } } if (sortField == 2) { if (studentsList.Count > 0) { string lastWord = studentsListTab[0].LastName; int indexLastElement = 0; for (int j = count - 1; j >= 0; j--) { for (int i = 1; i < count - 1; i++) { int compare = 0; compare = String.Compare(lastWord, studentsListTab[i].LastName); if (compare > 0) { lastWord = studentsListTab[i].LastName; indexLastElement = i; } } string firstName = " "; string lastName = " "; string studentNumber = " "; float averageScore = 0; firstName = studentsListTab[indexLastElement].FirstName; lastName = studentsListTab[indexLastElement].LastName; studentNumber = studentsListTab[indexLastElement].StudentNumber; averageScore = studentsListTab[indexLastElement].AverageScore; Student studentCopy = new Student(firstName, lastName, studentNumber, averageScore); Student removeByIndex = studentsListTab[indexLastElement]; studentsList.Remove(removeByIndex); studentsListFinish[j] = studentCopy; } } if (sortDirection == 1) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddLast(student); } } if (sortDirection == 0) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddFirst(student); } } } if (sortField == 3) { if (studentsList.Count > 0) { string lastWord = studentsListTab[0].StudentNumber; int indexLastElement = 0; for (int j = count - 1; j >= 0; j--) { for (int i = 1; i < count - 1; i++) { int compare = 0; compare = String.Compare(lastWord, studentsListTab[i].StudentNumber); if (compare > 0) { lastWord = studentsListTab[i].StudentNumber; indexLastElement = i; } } string firstName = " "; string lastName = " "; string studentNumber = " "; float averageScore = 0; firstName = studentsListTab[indexLastElement].FirstName; lastName = studentsListTab[indexLastElement].LastName; studentNumber = studentsListTab[indexLastElement].StudentNumber; averageScore = studentsListTab[indexLastElement].AverageScore; Student studentCopy = new Student(firstName, lastName, studentNumber, averageScore); Student removeByIndex = studentsListTab[indexLastElement]; studentsList.Remove(removeByIndex); studentsListFinish[j] = studentCopy; } } if (sortDirection == 1) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddLast(student); } } if (sortDirection == 0) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddFirst(student); } } } if (sortField == 4) { if (studentsList.Count > 0) { float scoreMin = studentsListTab[0].AverageScore; int indexMinElement = 0; for (int j = count - 1; j >= 0; j--) { for (int i = 1; i < count - 1; i++) { if (scoreMin > studentsListTab[i].AverageScore) { scoreMin = studentsListTab[i].AverageScore; indexMinElement = i; } } string firstName = " "; string lastName = " "; string studentNumber = " "; float averageScore = 0; firstName = studentsListTab[indexMinElement].FirstName; lastName = studentsListTab[indexMinElement].LastName; studentNumber = studentsListTab[indexMinElement].StudentNumber; averageScore = studentsListTab[indexMinElement].AverageScore; Student studentCopy = new Student(firstName, lastName, studentNumber, averageScore); Student removeByIndex = studentsListTab[indexMinElement]; studentsList.Remove(removeByIndex); studentsListFinish[j] = studentCopy; } } if (sortDirection == 1) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddLast(student); } } if (sortDirection == 0) { for (int i = 0; i < count; i++) { Student student = studentsListFinish[i]; studentsList.AddFirst(student); } } } }