/** * student-compare.c * Some simple comparators for students. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include "student.h" #include "student-compare.h" // +-------------+---------------------------------------------------- // | Comparators | // +-------------+ int compare_students_by_debt (struct student *s, struct student *t) { if (s->debt < t->debt) return -1; else if (s->debt > t->debt) return 1; else return 0; } // compare_students_by_debt int compare_students_by_gpa (struct student *s, struct student *t) { if (s->gpa < t->gpa) return -1; else if (s->gpa > t->gpa) return 1; else return 0; } // compare_students_by_gpa int compare_students_by_name (struct student *s, struct student *t) { int lcmp = strcmp (s->lname, t->lname); // Normal case: Different last names if (lcmp) return lcmp; // Special case: Identical last names else return strcmp (s->fname, t->fname); } // compare_students_by_name int compare_students_by_student_id (struct student *s, struct student *t) { return strcmp (s->sid, t->sid); } // compare_students_by_student_id