Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class CrapVec {
- int size;
- int capacity;
- T *data;
- T *data_new;
- public:
- ~CrapVec ( )
- {
- delete[] data;
- }
- CrapVec ( )
- {
- size = 0;
- capacity = 1;
- T* data = new T[capacity];
- }
- T& operator[] (int index) {
- return data[index];
- }
- void PushBack (T x)
- {
- if (size >= capacity) {
- reallocate(capacity*2);
- capacity = capacity*2;
- }
- data[size++] = x;
- }
- void reallocate(size_t s)
- {
- if (s < capacity)
- {
- std::cout << "what are you doing mazafuka" << std::endl;
- return;
- }
- T* data_new = new T[s];
- for(int it = 0; it != size ; ++it)
- {
- data_new[it] = data[it];
- }
- delete[] data;
- data = data_new;
- }
- void Print()
- {
- std::cout << "Vactor values: ";
- for(int it = 0; it != size ; ++it)
- {
- std::cout << data[it] << ", ";
- }
- std::cout << "." << std::endl;
- }
- };
- int main()
- {
- CrapVec<int> myvec;
- myvec.PushBack(1);
- //myvec.PushBack(2);
- //myvec.PushBack(4);
- //myvec.Print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement