//以下是stack.hconst int StackMaxSize=30;typedef int ElemType;struct Stack{ ElemType stack[StackMaxSize]; int top;};void InitStack(Stack& s){ s.top=-1;}void ClearStack(Stack& s){ s.top=-1;}int StackEmpty(Stack& s){ return s.top==-1;}ElemType Peek(Stack& s){ if(s.top==-1) { cerr<<"Stack is empty!"<<endl; exit(1); }return s.stack[s.top];}void Push(Stack& s,const ElemType& item){ if(s.top==StackMaxSize-1) { cerr<<"Stack overflow!"<<endl; exit(1); } s.top++; s.stack[s.top]=item;}ElemType Pop(Stack& s){ if(s.top==-1){ cerr<<"Stack is empty!"<<endl; exit(1); } ElemType temp=s.stack[s.top];s.top--;return temp;}int StackFull(Stack& s){ return s.top==StackMaxSize-1;}//以下是stack.cpp#include<iostream.h>//栈的简单应用,从键盘上输入一批整数,然后按照相反的次序打印出来#include<stdlib.h>#include"stack.h"#include<conio.h>void main(){ Stack a; InitStack(a); int x;cout<<"输入30个以下的整数,用-1作为终止键盘输入"<<endl; cin>>x; while(x!=-1){ //假定用-1作为终止键盘输入的标志,输入的整数个数不能超过StackMaxSize所规定的值 Push(a,x); cin>>x; } while(!StackEmpty(a)) cout<<Pop(a)<<" "; cout<<endl; getch();}/*http://f2.9612.org//vcpp/webinfo/WebInfoBata1.aspQQ群:34409541 讨论网页 34409326 讨论JAVA 已满 34408784 讨论VC++ 34409699 讨论VC++ 9143041 讨论MFC编程 10614204 讨论C# 10613030 讨论Win32编程 10613067 讨论游戏开发 18779860 讨论JAVA */