qq_31987003 2015-11-14 06:19 采纳率: 0%
浏览 2448

这个代码在编译时没有错误,在运行时却弹出debug assertion failed line52

#ifndef Linkstack_H
#define Linkstack_H
#include
using namespace std;
template
struct Node
{
T data;
Nodenext;
};
template
class LinkStack
{
public:
LinkStack();//{top=NULL;}
~LinkStack();
void Push(T x);
T Pop();
T GetTop();
int Empty();//{top=NULL?return 1:return 0;}
private:
Node
top;
};
#endif

#include
using namespace std;
#include"Link.h"
template
LinkStack::LinkStack()
{
top=new Node;
top=NULL;
}
template
void LinkStack::Push(T x)
{
Node*s;
s=new Node;
s->data=x;
s->next=top;
top=s;
}
template
T LinkStack::Pop()
{
Node*p;
p=new Node;
if(top==NULL)throw"下溢";
int x=top->data;
p=top;
delete p;
return x;
}
template
LinkStack::~LinkStack()
{
while(top)
{
Node*p;
p=top->next;
delete top;
top=p;
}
}
template
T LinkStack::GetTop()
{
if(top!=NULL)
return top->data;
else
return 0;
}
int main()
{
LinkStack x;
try
{
x.Push(1);
x.Push(2);
x.Push(8);
cout<<x.GetTop()<<endl;
x.Pop();
cout<<x.GetTop()<<endl;
x.Pop();
x.Pop();
x.Pop();
x.Empty();
cout<<x.GetTop()<<endl;
}
catch(char*wrong)
{
cout<<wrong;
}
}

  • 写回答

4条回答 默认 最新

  • threenewbee 2015-11-14 06:27
    关注

    就你这代码还编译没问题?
    int Empty()的实现在哪里?
    top=NULL?return 1:return 0;
    这种写法也能编译?

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?