-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec.h
56 lines (37 loc) · 926 Bytes
/
Vec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#ifndef NUMERIK0_VEC_H
#define NUMERIK0_VEC_H
class Vec {
int capacity;
int size;
double *data;
public:
Vec() {
this->capacity = 10;
this->size = 0;
double *data;
this->data = new double[10];
}
void push_back(double x) {
// std::cout << "next" << std::endl;
if (size < capacity) {
data[size] = x;
this->size++;
} else {
double *newarray;
newarray = new double[2 * capacity];
for (int i = 0; i < capacity; ++i) {
newarray[i] = data[i];
}
newarray[capacity] = x;
delete[] data;
data = newarray;
capacity = capacity * 2;
}
// for (int j = 0; j < capacity; ++j) {
//
// std::cout << data[j] << std::endl;
// }
}
};
#endif //NUMERIK0_VEC_H