template<class T>标签:head,VC,next,dat,Link,堆栈,data,Stack From: https://blog.51cto.com/kenkao/5989781
class Stack{
struct Link{
T* data;
Link* next;
Link(T* dat,Link* nxt):data(dat),next(nxt){}
}*head;
public:
Stack():head(0){}
~Stack(){
while(head)
delete pop();
}
void push(T* dat)
{
head=new Link(dat,head);
}
T* peek() const{
return head?head->data:0;
}
T* pop(){
if(head==0) return 0;
T* result=head->data;
Link* oldHead=head;
head=head->next;
delete oldHead;
return result;
}
};