Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- struct MyObject {
- MyObject(int a, std::string b, bool c) : a(a), b(b), c(c) {}
- int a;
- std::string b;
- bool c;
- };
- //Vergleichsfunktion
- bool compare(MyObject const& obj1, MyObject const& obj2) {
- return obj1.a < obj2.a;
- }
- int main() {
- std::list<MyObject> table;
- table.push_back(MyObject(10, "Hello", false));
- table.push_back(MyObject(5, "World", true));
- table.push_back(MyObject(6, "noch", false));
- table.push_back(MyObject(-5, "mehr", false));
- table.push_back(MyObject(2, "Text", true));
- table.sort(compare);
- //Tabelle ausgeben
- for (std::list<MyObject>::iterator iter = table.begin(); iter != table.end(); iter++) {
- std::cout << iter->a << ", " << iter->b << ", " << (iter->c ? "true" : "false") << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement