头文件
#include <iostream>
using namespace std;
#ifndef Dynamic_Num
#define Dynamic_Num
template <class T>
class DynamicVector{
public:
template<class Y>
friend ostream &operator<<(ostream &out, const DynamicVector<Y> &obj);
DynamicVector() : array(NULL), mallocSize(0), numOfItems(0), virtualZero(0) {
}
DynamicVector(int index) : array(NULL), mallocSize(0), numOfItems(0), virtualZero(index) {
}
DynamicVector(T * const begin, T * const end,int index=0);
DynamicVector(const DynamicVector &obj);
DynamicVector<T> operator()(int begin, int end);
//~DynamicVector() { if(array&&numOfItems) delete[] array; }
void Reset(unsigned int size);
void Copy_Basic(const DynamicVector<T> &obj);
DynamicVector<T> &operator=(const DynamicVector<T> &obj);
unsigned int length() const {
return numOfItems; }
unsigned int capacity() const {
return mallocSize; }
int firstIndex() const {
return virtualZero; }
T *begin() const {
return &array[0]; }
T *end() const {
return &array[numOfItems]; }
T &operator[](int index);
bool operator==(const DynamicVector<T> &obj) const;
void swap(DynamicVector<T> &obj);
void insert(int index, const T &obj);
inline void push_back(const T &obj);
void push_back(const DynamicVector<T> &obj);
void remove();
void remove(int index);
void remove(int begin, int end);
private:
T *array = NULL;
unsigned int mallocSize = 0, numOfItems = 0;
int virtualZero = 0;
};
template<typename T>
DynamicVector<T>:: DynamicVector(T * const begin, T * const end,int index):numOfItems(end-begin),virtualZero(index){