就是这个了,望采纳。#ifndef STACK_H#define STACK_Husing namespace std;templateclass stack{ public: stack(){head=NULL; n=0;} virtual ~stack(){head=NULL;} int length(){return n;} bool push(elemtype& );//入栈 elemtype pop();//出栈 bool empty(){return head==NULL;} void clear(); protected: int n; struct node{ node *next; elemtype data; }; node *head;};templatevoid stack::clear(){ node *p,*q; int i=1; p=head; while(i!=n) { q=p; delete q; p=p->next; i++; }}templatebool stack::push(elemtype &e){ node *p,*q; int j=1; if(head==NULL) head=new node; p=head; if(n==0)//表头赋值 {head->data=e; n++; return true;} else //表尾插入 { q=new node; q->data=e; while (jnext; j++; } p->next=q; q->next=NULL; n++; return true;}
}templateelemtype stack::pop( ){ int j=1; node *p; p=head; while(jnext; j++; } n--; return p->data;}
#endif // stack_H