#include <iostream>
using namespace std;
class node
{
friend class Linkstack;
private:
long data;
node * next;
};
class Linkstack
{
public:
Linkstack();
~Linkstack();
void destroy();
void push(long item);
void pop();
private:
node *Stacktop;
int Stacklength;
};
Linkstack::Linkstack()
{
Stacktop = new node;
Stacklength = 0;
}
Linkstack::~Linkstack()
{
destroy();
delete Stacktop;
}
void Linkstack::destroy()
{
for(int i = 0;i < Stacklength; i++)
{
pop();
}
}
/****************进栈***************/
void Linkstack::push(long item)
{
node *newnodep = new node;
newnodep->data = item;
newnodep->next = Stacktop;
Stacktop = newnodep;
Stacklength++;
}
/****************出栈******************/
void Linkstack::pop()
{
node * popnodep = Stacktop->next ;
delete Stacktop;
Stacktop = popnodep;
Stacklength--;
}