Based on the definition of Dynamic Array in Problem 13520 (nthu.edu.tw), you need to implement a dynamic array with the following functions:
Note that, two new functions void popback(void) and int back(void) are introduced in this problem.
// function.h
class Darray {
public:
Darray() {
capacity = 100;
size = 0;
data = new int[capacity];
};
~Darray();
int& operator[](int);
void pushback(int x);
void popback(void);
void clear(void);
int length(void);
int back(void);
void print(void){
if(this->size == 0){
cout << endl;
}
else{
for(int i=0; i<this->size; i++){
cout << this->data[i] << " ";
}
cout << endl;
}
};
private:
void resize(void); // double the capacity
int *data;
int capacity;
int size;
};
Each command is followed by a new line character.
("pushback", "popback" and "clear" will not print anything)