| 1 | class Vector{ |
| 2 | int *arr; |
| 3 | int ms; |
| 4 | int cs; |
| 5 | public: |
| 6 | Vector(int size=1){ |
| 7 | cs=0; |
| 8 | ms=size; |
| 9 | arr= new int[ms]; |
| 10 | } |
| 11 | void push_back(int d){ |
| 12 | if(cs==ms){ |
| 13 | int *oldArr=arr; |
| 14 | ms*=2; |
| 15 | arr= new int[ms]; |
| 16 | //copy the old items to the new array of double size |
| 17 | for (int i = 0; i < cs; i++) { |
| 18 | arr[i]=oldArr[i]; |
| 19 | } |
| 20 | delete []oldArr; |
| 21 | } |
| 22 | arr[cs]=d; |
| 23 | cs++; |
| 24 | } |
| 25 | void pop_back(){ |
| 26 | if(cs>=0){ |
| 27 | cs--; |
| 28 | } |
| 29 | |
| 30 | } |
| 31 | bool isEmpty(){ |
| 32 | return cs==0; |
| 33 | } |
| 34 | int Front(){ |
| 35 | return arr[0]; |
| 36 | |
| 37 | } |
| 38 | int back(){ |
| 39 | return arr[cs-1]; |
| 40 | } |
| 41 | int at(int i){ |
| 42 | return arr[i]; |
| 43 | } |
| 44 | int size(){ |
| 45 | return cs; |
| 46 | } |
| 47 | int capacity(){ |
| 48 | return ms; |
| 49 | } |
| 50 | int operator[](const int i) const{ |
| 51 | return arr[i]; |
| 52 | } |
| 53 | |
| 54 | |
| 55 | }; |
| 56 | |
| 57 | |
| 58 |
nothing calls this directly
no outgoing calls
no test coverage detected