C++改错,在线等,急!!!!!!! 20

#include<iostream>usingnamespacestd;template<classT>classChainNode{friendclassChain;p... #include <iostream>

using namespace std;

template<class T>
class ChainNode{
friend class Chain;
private:
T data;
ChainNode<T> *link;
};

class OutOfBounds{};

template<class T>
class Chain{
public:
Chain(){first=0;}
~Chain();
bool IsEmpty()const{return first==0;}
int length()const;
bool find(int k,T&x)const;
int Search(const T&x)const;
Chain<T>&Delete(int k,T&x);
Chain<T>&Insert(int k,const T&x);
Chain<T>&Reverse();
Chain<T>&Merge(Chain<T>&A,Chain<T>B,Chain<T>C);
void Output(ostream&out)const;
private:
ChainNode<T> *first;
};

template<class T>
Chain<T>::~Chain(){
ChainNode<T> *next;
while(first){
next=first->link;
delete first;
first=next;
}
}
template<class T>
int Chain<T>::length()const{
int len;
ChainNode<T> *current=first;
while(current){
len++;
current=current->link;
}
return len;
}

template<class T>
bool Chain<T>::find(int k,T&x)const{
if(k<1) return false;
ChainNode<T> *current=first;
int i=1;
while(i<k&¤t){
current=current->link;
i++;
}
if(current){x=current->data;return true;}
return false;
}

template<class T>
int Chain<T>::Search(const T&x)const{
int index=1;
ChainNode<T> *current=first;
while(current&¤t->data!=x){
current=current->link;
index++;
}
if(current)return index;
return 0;
}
template<class T>
Chain<T>&Chain<T>::Delete(int k,T&x){
if(k<1||!first)throw OutOfBounds();
ChainNode<T> *p=first;
if(k==1) first=first->link;
else{
ChainNode<T> *q=first;
for(int index=1;index<k-1;index++)
q=q->link;
if(!q||!q->link)throw OutOfBounds();
p=q->link;
q->link=p->link;}
x=p->data;
delete p;
return *this;
}

template<class T>
Chain<T>&Chain<T>::Insert(int k,const T&x){
if(k<0)throw OutOfBounds();
ChainNode<T> *p=first;
for(int index=0;index<k-1;index++)
p=p->link;
if(!p)throw OutOfBounds();
ChainNode<T> *y=new ChainNode<T>;
y->data=x;
if(k){
y->link=p->link;
p->link=y;
}
else {
y->link=first;
first=y;}
return *this;

}
template<class T>
void Chain<T>::Output(ostream&out)const{
ChainNode<T> *current;
for(current=first;current;current=current->link)
out<<current->data<<" ";
}

template<class T>
ostream operator<<(ostream &out,const Chain<T>&x){
x.Output(out);
return out;
}
template<class T>
Chain<T>&Chain<T>::Reverse(){
ChainNode<T> *last=0,*current=first,*next;
while(current){
next=current->link;
current->link=last;
last=current;
current=next;
}
last=first;
return *this;
}
template<class T>
Chain<T>&Chain<T>::Merge(Chain<T>&A,Chain<T>B,Chain<T> C){
ChainNode<T> *p=A.first,*q=B.first,*current;
int i=0,j=0,k=0;
while(i<A.length()&&j<B.length()){
if(p->data<q.data){
C.Insert(k++,p->data);
p=p->link;}
else{
C.Insert(k++,q->data);
q=q->link;
}
while(q->link){
q=q->link;
C.Insert(k++,q->data);
}
while(p->link){
p=p->link;
C.Insert(k++,p->data);
}
}
return *C;

}

int main()
{
Chain<int> x;
x.Insert(0,3).Insert(1,2);
x.Output(cout);
}
这段代码有哪些错呢??我是新手,运行一大堆报错,急求解答,谢谢
展开
 我来答
linman2010
2010-11-12 · TA获得超过302个赞
知道小有建树答主
回答量:525
采纳率:100%
帮助的人:303万
展开全部
?这是一个做什么的程序?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式