stack.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //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;
- }