自己构建一个vector函数

#include<iostream>
#include<malloc.h>
using namespace std;
template<typename T>
class Vector{
   private:T *p;
   int size;
   int n;
   public:
     Vector()
    {p=(T*)malloc(10*sizeof(T));
    size=10;
    n=0;}
    void Push_back(const T a){
    if(n==size){p=(T*)realloc(p,10*sizeof(T));size+=10;}
    *(p+n)=a;
    n++;
    }
    typedef T* Iterator;
    T* Begin()
    {return p;}
    T* End()
    {return p+n;}
};

 

posted @ 2018-02-03 20:35  myyismyy  阅读(131)  评论(0编辑  收藏  举报