Facebook
From Sharp Giraffe, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 208
  1. template <class T, class T2>
  2. class Iterator
  3. {
  4. public:
  5.         friend class Kontener;
  6.         T (**wsk);
  7. protected:
  8.  
  9.         int actual;
  10.         T2 &container;
  11. public:
  12.         Iterator(T2 &cont):container(cont)
  13.         {
  14.                 wsk = cont.tab;
  15.                 actual = 0;
  16.         }
  17.         Iterator & na_poczatek()
  18.         {
  19.                 wsk = container.tab;
  20.                 actual = 0;
  21.                 return *this;
  22.         }
  23.         Iterator & na_koniec()
  24.         {
  25.                 wsk = (container.tab + (SIZE-1));
  26.                 actual = SIZE-1;
  27.                 return *this;
  28.         }
  29.         Iterator & za_koniec()
  30.         {
  31.                 wsk = NULL;
  32.                 actual = -1;
  33.                 return *this;
  34.         }
  35.         Iterator & na_wezel(int indeks)
  36.         {
  37.                 wsk = (container.tab + (indeks));
  38.                 actual = indeks;
  39.                 return *this;
  40.         }
  41.         Iterator & operator++()
  42.         {
  43.                 if(wsk && actual<(SIZE - 1))
  44.                 {
  45.                         wsk = (container.tab + (actual + 1));
  46.                         actual += 1;
  47.                 }
  48.                 else
  49.                         cout<<"Iterator jest juz na ostatnim miejscu lub jest poza tablica."<<endl;
  50.                 return *this;          
  51.         }
  52.         Iterator & operator--()
  53.         {
  54.                 if(wsk && actual>0)
  55.                 {
  56.                         wsk = (container.tab + (actual - 1));
  57.                         actual -= 1;
  58.                 }
  59.                 else
  60.                         cout<<"Iterator jest juz na pierwszym miejscu lub jest poza tablica."<<endl;
  61.                 return *this;          
  62.         }
  63.         Iterator & operator*(int liczba)
  64.         {
  65.                 cout<<endl<<"actual: "<<actual<<endl;
  66.                 if(wsk && (liczba * actual < SIZE))
  67.                 {
  68.                         wsk = (container.tab + (liczba * actual));
  69.                         actual = liczba * actual;
  70.                 }
  71.                 else
  72.                         cout<<"Iterator jest poza tablica."<<endl;
  73.                 return *this;
  74.         }
  75.         Iterator & operator=(Iterator &it)
  76.         {
  77.                 if(&it == this)
  78.                         cout<<"To ten sam iterator."<<endl;
  79.                 else
  80.                         {
  81.                                 this->actual = it.actual;
  82.                                 **this->wsk = **it.wsk;
  83.                                
  84.                         }
  85.                 return *this;          
  86.         }
  87.         Iterator & operator==(Iterator &it)
  88.         {
  89.                 if(&it == this)
  90.                         cout<<"To ten sam iterator."<<endl;
  91.                 else
  92.                         {
  93.                                 if(this->actual == it.actual)
  94.                                         cout<<"Sa takie same."<<endl;
  95.                                 else
  96.                                         cout<<"Nie sa takie same."<<endl;
  97.                         }
  98.                 return *this;          
  99.         }
  100.         Iterator & operator!=(Iterator &it)
  101.         {
  102.                 if(&it == this)
  103.                         cout<<"To ten sam iterator."<<endl;
  104.                 else
  105.                         {
  106.                                 if(this->actual != it.actual)
  107.                                         cout<<"Sa rozne."<<endl;
  108.                                 else
  109.                                         cout<<"Sa takie same."<<endl;
  110.                         }
  111.                 return *this;          
  112.         }
  113.         operator int() const
  114.         {
  115.                 return int(actual);
  116.         }
  117.         void wypisz()
  118.         {
  119.                 cout<<"ITERATOR "<<**wsk<<endl;
  120.         }
  121. };