在C语言中,可以使用sort函数对vector进行排序。下面是一个示例代码: #include <stdio.h> #include <stdlib.h> // 比较函数,用于sort函数的第三个参数 int compare(const void *a, const void *b) { return (*(int*)a - *(int*)b); } int main() { int arr[] = {5, 2, 8, 1, 9}; int...
struct StudentScore{ std::string name; int score;}std::vector<StudentScore> students;//添加元素,略std::sort(students.begin(),students.end(),[](const StudentScore& first,const StudentScore& second)->bool{ if(first.score < second.first) return true; else if(first....