#include<iostream.h> typedef struct node { char ch; node *next; }*ptrn; class stack { private: int count; char ch1; ptrn head,newnode,p1; public: stack() { count=0; head=new node; } void input() { int n; count=0; ptrn temp; while(1) { cout<<"1表示继续输入,-1表示终止输入"<<endl; cin>>n; if(n==-1) break; else { cout<<"请输入元素"<<endl; cin>>ch1; newnode=new node; newnode->ch=ch1; if(p1==0) { p1=newnode; head->next=p1; } else { temp=head->next; head->next=newnode; newnode->next=temp; } count++; } } } int length() { return count; } bool empty() { return count==0; } void output() { ptrn tem; tem=head; for(int i=0;i<length();i++) { cout<<tem->next->ch<<endl; tem=tem->next; } } void release() { for(int i=0;i<length();i++) { ptrn t; t=head; head=head->next; delete t; } } }; void main() { stack stack1; stack1.input(); stack1.length(); stack1.output(); stack1.release(); }