Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. using namespace std;
  5.  
  6. class Miasto{
  7. public:
  8. std::string name;
  9. int population;
  10. };
  11.  
  12. bool f(const Miasto& a,const Miasto& b)
  13. {
  14. return a.population<b.population;
  15. }
  16.  
  17. class Iterator{
  18. list<Miasto> lista;
  19. list<Miasto>::iterator it;
  20. public:
  21. Iterator(const list<Miasto>& l){
  22. lista=l;
  23. lista.sort(f);
  24. it=lista.begin();
  25. }
  26. operator bool(){
  27. return it!=lista.end();
  28. }
  29. void operator ++(){
  30. it++;
  31. }
  32. Miasto* get(){
  33. return &(*it);
  34. }
  35. };
  36.  
  37. int _tmain(int argc, _TCHAR* argv[])
  38. {
  39. list<Miasto> l;
  40. Miasto m1={"xx",4};
  41. Miasto m2={"rr",2};
  42. l.push_back(m1);
  43. l.push_back(m2);
  44. Iterator it(l);
  45. while(it){
  46. cout<<it.get()->name<<endl;
  47. ++it;
  48. }
  49. system("pause");
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement