qq_38397675 2017-04-20 03:22
浏览 533

为什么在派生类中基类定义的head tail 没用了 新人求解

#include
#include
using namespace std;
template
struct Node{
T data;
Node*prior;
Node*next;
};
template
class list{
public:
Node*head;
Node*tail;
list()
{
head=tail=NULL;
}
virtual void store(T i)=0;
virtual T retrieve()=0;
};

template
class queue:public list{
public:
void store(T i);
T retrieve();
};

template
void queue::store(T i)
{
Node*item;
item=new Node;
if(!item)
{
cout<<"error"< }
item->data=i;
if(!head)
{
item->prior=head;
head=tail=item;
item->next=NULL;
}
item->prior=tail;
tail->next=item;
tail=item;
item->next=NULL;
}

template
T queue::retrieve()
{
T temp;
Node*p;
if(!head)
{
cout<<"队列已空"< }
temp=head->data;
p=head;
head=head->next;
head->prior=NULL;
delete p;
return temp;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services