Skip to content

Instantly share code, notes, and snippets.

@Petingo
Created November 27, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Petingo/8ad07f7c0dd77dac01485bdc105b4b58 to your computer and use it in GitHub Desktop.
Save Petingo/8ad07f7c0dd77dac01485bdc105b4b58 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
class Student {
public:
int no;
string name;
Student() = default;
Student(int no, string name) {
this->no = no;
this->name = name;
}
bool operator<(const Student &other) const { return this->no < other.no; }
};
int main() {
Student student[3] = {{3, "Terry"}, {1, "Tom"}, {2, "Dickson"}};
sort(student, student + 3);
for (int i = 0; i < 3; i++) {
cout << student[i].no << " " << student[i].name << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment