!-- flowchart 箭头图标 勿删 --
//stackLink.h
#ifndef STACKLINK_H_INCLUDED
#define STACKLINK_H_INCLUDED
template <typename T>
class Node
{
public:
T data;
Node<T>* next;
};
template <typename T>
class StackLink{
private:
Node<T> *head;
public:
void push(T data);
T pop();
bool isEmpty();
StackLink(){
head=new Node<T>();
head->data=-1;
head->next=0;
}
~StackLink(){delete head;}
};
template <typename T>
void StackLink<T>::push(T data)
{
Node<T> *p=new Node<T>();
p->data=data;
p->next=head->next;
head->next=p;
}
template <typename T>
T StackLink<T>::pop()
{
T res;
res=head->next->data;
head->next=head->next->next;
delete head->next;
return res;
}
template <typename T>
bool StackLink<T>::isEmpty()
{
return head->next==0;
}
#endif // STACKLINK_H_INCLUDED
//stack