用队列结构解决杨辉三角问题,C++,出错0
xcjk12014.02.20浏览59次分享举报
#ifndef LINKQUEUE_H
#define LINKQUEUE_H
#include
#include
#include
using namespace std;
template
class LinkQueueNode{
public:
T data;
LinkQueueNode* link;
LinkQueueNode(T& value):data(value),link(NULL){}
};
template
class LinkQueue{
LinkQueueNode* front;
LinkQueueNode* back;
public:
LinkQueue():front(NULL),back(NULL){}
void EnQueue(T& element);
T DelQueue();
T& GetFront();
void MakeEmpty();
bool IsEmpty();
};
template
void LinkQueue::EnQueue(T& value)
{
LinkQueueNode* add = new LinkQueueNode(value);
if(back == NULL)
{
front = back = add;
}
else
{
back->link = add;
back = back->link;
}
}
template
T LinkQueue::DelQueue()
{
assert(!IsEmpty());
LinkQueueNode* old = front;
T data = old->data;
front = front->link;
if(back == old)
back = NULL;
delete old;
return
data;
}
template
T& LinkQueue::GetFront()
{
assert(!IsEmpty());
return
front->data;
}
template
void LinkQueue::MakeEmpty()
{
while(!this->IsEmpty()){
this->DelQueue();
}
}
template
bool LinkQueue::IsEmpty()
{
return
front == NULL;
}
#endif
.cpp
#include "LinkQueue.h"
using namespace std;
template
void evaluate(LinkQueue& ori,LinkQueue& target){
ori.MakeEmpty();
while(!target.IsEmpty()){
ori.EnQueue(target.DelQueue());
}
}
int main(){
cout<2):";
int num;
cin>>num;
LinkQueue ori;
ori.EnQueue(1);
ori.EnQueue(1);
LinkQueue next;
for(int i=0;i
next.EnQueue(1);
while(!ori.IsEmpty()){
int i=ori.DelQueue();
if(!ori.IsEmpty())
next.EnQueue(i+ori.GetFront());
if(ori.IsEmpty())
next.EnQueue(i);
}
evaluate(ori,next);
}
cout<
while(!ori.IsEmpty()){
cout<
}
cout<
return 0;
}
Error 1 error C2664: 'LinkQueue::EnQueue' : cannot convert parameter 1 from 'int' to 'int &' e:\cpwork\实例\杨辉三角\杨辉三角\杨辉三角.cpp 18
Error 2 error C2664: 'LinkQueue::EnQueue' : cannot convert parameter 1 from 'int' to 'int &' e:\cpwork\实例\杨辉三角\杨辉三角\杨辉三角.cpp 19
Error 3 error C2664: 'LinkQueue::EnQueue' : cannot convert parameter 1 from 'int' to 'int &' e:\cpwork\实例\杨辉三角\杨辉三角\杨辉三角.cpp 22
Error 4 error C2664: 'LinkQueue::EnQueue' : cannot convert parameter 1 from 'int' to 'int &' e:\cpwork\实例\杨辉三角\杨辉三角\杨辉三角.cpp 26
请问错误怎么解决啊