36 lines
438 B
C++
36 lines
438 B
C++
#ifndef DATA_VECTOR_H
|
|
#define DATA_VECTOR_H
|
|
|
|
#include <cstdint>
|
|
|
|
template <typename T> class Vector {
|
|
|
|
private:
|
|
|
|
T* data = nullptr;
|
|
size_t nextIdx = 0;
|
|
size_t total = 8;
|
|
|
|
public:
|
|
|
|
Vector() {
|
|
data = (T*) malloc(total*sizeof(T));
|
|
}
|
|
|
|
void push_back(T elem) {
|
|
data[nextIdx] = elem;
|
|
++nextIdx;
|
|
}
|
|
|
|
T& operator[] (const size_t idx) {
|
|
return data[idx];
|
|
}
|
|
|
|
size_t size() const {
|
|
return nextIdx;
|
|
}
|
|
|
|
};
|
|
|
|
#endif // DATA_VECTOR_H
|