stack.cpp
来自「本文档是(作者:钱能)《C++程序设计教程》课后习题答案。 选题编辑:张朝阳 」· C++ 代码 · 共 38 行
CPP
38 行
//stack.cpp
#include "stack.h"
#include <stdlib.h>
#include <iostream.h>
Stack::Stack():head(NULL){}
void Stack::Put(int item)
{
Node* p = new Node;
p->a = item;
p->next = head;
head = p;
}
Stack::~Stack()
{
for(Node* p=head; p;){
Node* t = p;
p=p->next;
delete t;
}
}
int Stack::Get()
{
if(!head){
cerr <<"error access stack underflow.\n";
exit(1);
}
int result = head->a;
Node* p = head;
head = head->next;
delete p;
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?