Guest User

Untitled

a guest
May 26th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<string>
  2.  
  3. class Sentence {
  4.     string str;
  5. public:
  6.     Sentence(string a):str(a){};
  7. };
  8.  
  9. class InSentence: public Sentence {
  10. public:
  11.     InSentence(string a):str(a){};
  12. };
  13.  
  14. class Vector {
  15.     typedef Element *Sentence;
  16.     Element *array;
  17.     int m_size;
  18. public:
  19.     typedef Element *iterator;
  20.     Vector() : array(0), m_size() {}
  21.     ~Vector() {
  22.         delete[] array;
  23.     }
  24.  
  25.     void append(Sentence* a_s) {
  26.         Element* new_array = new Element[m_size + 1];
  27.         if(array) {
  28.             for(int i = 0; i < size; i++)
  29.                 new_array[i] = array[i];
  30.             delete[] array;
  31.         }
  32.         new_array[m_size] = a_s;
  33.         array = new_array;
  34.         m_size++;
  35.     }
  36.  
  37.     int size() const
  38.         { return size; }
  39.  
  40.     Element oprator[](int a_index) {
  41.         assert( a_index >= 0 && a_index < size() )
  42.         return array[a_index];
  43.     }
  44.  
  45.     iterator begin() {
  46.         return array;
  47.     }
  48.     iterator end() {
  49.         return array + size + 1;
  50.     }
  51. };
Add Comment
Please, Sign In to add comment