Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- using namespace std;
- class Miasto{
- public:
- std::string name;
- int population;
- };
- bool f(const Miasto& a,const Miasto& b)
- {
- return a.population<b.population;
- }
- class Iterator{
- list<Miasto> lista;
- list<Miasto>::iterator it;
- public:
- Iterator(const list<Miasto>& l){
- lista=l;
- lista.sort(f);
- it=lista.begin();
- }
- operator bool(){
- return it!=lista.end();
- }
- void operator ++(){
- it++;
- }
- Miasto* get(){
- return &(*it);
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- list<Miasto> l;
- Miasto m1={"xx",4};
- Miasto m2={"rr",2};
- l.push_back(m1);
- l.push_back(m2);
- Iterator it(l);
- while(it){
- cout<<it.get()->name<<endl;
- ++it;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement