VC 模板问题!!!在线等 高手进
#include<iostream>usingnamespacestd;template<typenameT>classvector{private:T*p;intlen...
#include<iostream>
using namespace std;
template <typename T>
class vector
{
private:
T *p;
int length;
public:
vector(int n=0);
vector(int n,T a);
vector(vector <T> & b);
friend T& operator[](vector &,int);
vector& operator=(vector <T> &aa);
friend bool operator ==(vector <T> &aa,vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};
template <typename T>
T& operator[](vector &c,int ii)
{
return c[ii];
}
template <typename T>
vector<T>::vector(int n = 0)
{
length=n;
p=new T[length];
}
template <typename T>
vector<T>::vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}
template <typename T>
vector<T>::vector(vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}
template <typename T>
vector& vector<T>::operator=(vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}
template <typename T>
bool operator==(vector <T>&aa,vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}
template <typename T>
T * vector<T>::begin()
{
return p;
}
template <typename T>
T* vector<T>::end()
{
return p[length];
}
template <typename T>
void vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}
template <typename T>
bool vector<T>::erase(T *x)
{
if(x-vector::begin()<0||x-vector::begin())
return false;
else
{
for(int i=x-vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool vector<T>::erase (T *x,T *y)
{
if(x-vector::begin()<0||y-vector::begin()>0)
return false;
else
{
for(int i=x-vector::begin();i<length-((y-vector::begin())-(x-vector::begin()));i++)
p[i]=p[i+(y-vector::begin())-(x-vector::begin())];
length=length-((y-vector::begin())-(x-vector::begin()));
return ture;
}
}
int main()
{
return 0;
}
帮我调试下啊 环境是VS2005
答的好一定加分 展开
using namespace std;
template <typename T>
class vector
{
private:
T *p;
int length;
public:
vector(int n=0);
vector(int n,T a);
vector(vector <T> & b);
friend T& operator[](vector &,int);
vector& operator=(vector <T> &aa);
friend bool operator ==(vector <T> &aa,vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};
template <typename T>
T& operator[](vector &c,int ii)
{
return c[ii];
}
template <typename T>
vector<T>::vector(int n = 0)
{
length=n;
p=new T[length];
}
template <typename T>
vector<T>::vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}
template <typename T>
vector<T>::vector(vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}
template <typename T>
vector& vector<T>::operator=(vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}
template <typename T>
bool operator==(vector <T>&aa,vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}
template <typename T>
T * vector<T>::begin()
{
return p;
}
template <typename T>
T* vector<T>::end()
{
return p[length];
}
template <typename T>
void vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}
template <typename T>
bool vector<T>::erase(T *x)
{
if(x-vector::begin()<0||x-vector::begin())
return false;
else
{
for(int i=x-vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool vector<T>::erase (T *x,T *y)
{
if(x-vector::begin()<0||y-vector::begin()>0)
return false;
else
{
for(int i=x-vector::begin();i<length-((y-vector::begin())-(x-vector::begin()));i++)
p[i]=p[i+(y-vector::begin())-(x-vector::begin())];
length=length-((y-vector::begin())-(x-vector::begin()));
return ture;
}
}
int main()
{
return 0;
}
帮我调试下啊 环境是VS2005
答的好一定加分 展开
展开全部
#include<iostream>
using namespace std;
template <typename T>
class Vector
{
private:
T *p;
int length;
public:
Vector(int n=0);
Vector(int n,T a);
Vector(Vector <T> & b);
T& operator [](int);
Vector<T>& operator = (Vector <T> &aa);
friend bool operator ==(Vector <T> &aa,Vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};
template <typename T>
T& Vector<T>::operator[](int ii)
{
return c[ii];
}
template <typename T>
Vector<T>::Vector(int n)
{
length=n;
p=new T[length];
}
template <typename T>
Vector<T>::Vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}
template <typename T>
Vector<T>::Vector(Vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}
template <typename T>
Vector<T>& Vector<T>::operator=(Vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}
template <typename T>
bool operator==(Vector <T>&aa,Vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}
template <typename T>
T * Vector<T>::begin()
{
return p;
}
template <typename T>
T* Vector<T>::end()
{
return p[length];
}
template <typename T>
void Vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-Vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}
template <typename T>
bool Vector<T>::erase(T *x)
{
if(x-Vector::begin()<0||x-Vector::begin())
return false;
else
{
for(int i=x-Vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool Vector<T>::erase (T *x,T *y)
{
if(x-Vector::begin()<0||y-Vector::begin()>0)
return false;
else
{
for(int i=x-Vector::begin();i<length-((y-Vector::begin())-(x-Vector::begin()));i++)
p[i]=p[i+(y-Vector::begin())-(x-Vector::begin())];
length=length-((y-Vector::begin())-(x-Vector::begin()));
return ture;
}
}
int main()
{
return 0;
}
using namespace std;
template <typename T>
class Vector
{
private:
T *p;
int length;
public:
Vector(int n=0);
Vector(int n,T a);
Vector(Vector <T> & b);
T& operator [](int);
Vector<T>& operator = (Vector <T> &aa);
friend bool operator ==(Vector <T> &aa,Vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};
template <typename T>
T& Vector<T>::operator[](int ii)
{
return c[ii];
}
template <typename T>
Vector<T>::Vector(int n)
{
length=n;
p=new T[length];
}
template <typename T>
Vector<T>::Vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}
template <typename T>
Vector<T>::Vector(Vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}
template <typename T>
Vector<T>& Vector<T>::operator=(Vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}
template <typename T>
bool operator==(Vector <T>&aa,Vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}
template <typename T>
T * Vector<T>::begin()
{
return p;
}
template <typename T>
T* Vector<T>::end()
{
return p[length];
}
template <typename T>
void Vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-Vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}
template <typename T>
bool Vector<T>::erase(T *x)
{
if(x-Vector::begin()<0||x-Vector::begin())
return false;
else
{
for(int i=x-Vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool Vector<T>::erase (T *x,T *y)
{
if(x-Vector::begin()<0||y-Vector::begin()>0)
return false;
else
{
for(int i=x-Vector::begin();i<length-((y-Vector::begin())-(x-Vector::begin()));i++)
p[i]=p[i+(y-Vector::begin())-(x-Vector::begin())];
length=length-((y-Vector::begin())-(x-Vector::begin()));
return ture;
}
}
int main()
{
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询