用队列实现杨辉三角 c语言,用队列结构解决杨辉三角问题,C++,出错

用队列结构解决杨辉三角问题,C++,出错0

02ae427d08e371d7e90d5b995e828d6d.pngxcjk12014.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

请问错误怎么解决啊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值