~cpp #include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; struct student{string name; int score;}; bool compare(student a, student b); bool compare2(student a, student b); void main() { student st[5]; st[0].name = "nj"; st[0].score = 76; st[1].name = "jk"; st[1].score = 66; st[2].name = "hj"; st[2].score = 78; st[3].name = "gh"; st[3].score = 73; vector<student> sp; sp.push_back(st[1]); sp.push_back(st[2]); sp.push_back(st[3]); sp.push_back(st[4]); sort(sp.begin(), sp.end(), compare); for(vector<student>::iterator i= sp.begin();i!=sp.end(); i++) cout << i->name <<"\t"<< i->score << endl; cout << "-------------------------------------"<<endl; sort(sp.begin(),sp.end(),compare2); for(i=sp.begin();i<sp.end();i++) cout << i->name<<"\t"<<i->score<< endl; } bool compare(student a, student b); { return a.name < b.name; } bool compare2(student a, student b); { return a.score < b.score; }