fork download
  1. template <typename T>
  2. class MyVector {
  3. private:
  4. T* data;
  5. int capacity;
  6. int size;
  7.  
  8. void resize() {
  9. capacity *= 2;
  10. T* newData = new T[capacity];
  11. for (int i = 0; i < size; ++i)
  12. newData[i] = data[i];
  13. delete[] data;
  14. data = newData;
  15. }
  16.  
  17. public:
  18. MyVector() : capacity(4), size(0) {
  19. data = new T[capacity];
  20. }
  21.  
  22. void push_back(T value) {
  23. if (size == capacity)
  24. resize();
  25. data[size++] = value;
  26. }
  27.  
  28. void pop_back() {
  29. if (size > 0)
  30. --size;
  31. }
  32.  
  33. void push_front(T value) {
  34. if (size == capacity)
  35. resize();
  36. for (int i = size; i > 0; --i)
  37. data[i] = data[i - 1];
  38. data[0] = value;
  39. ++size;
  40. }
  41.  
  42. void pop_front() {
  43. if (size == 0) return;
  44. for (int i = 0; i < size - 1; ++i)
  45. data[i] = data[i + 1];
  46. --size;
  47. }
  48.  
  49. T operator[](int index) const {
  50. return data[index];
  51. }
  52.  
  53. int getSize() const {
  54. return size;
  55. }
  56. };
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty