#include<iostream> #include<string> #include<stdio.h> #include<stdlib.h> using namespace std; #define True 1 #define False 0 #define OK 1 #define Error -1 #define Overflow -2 #define Stack_Init_Size 100 #define StackIncrement 10 typedef struct { string *base; string *top; int stackSize; }Stack; void InitStack(Stack &s) { s.base=(string *)malloc(Stack_Init_Size*sizeof(string)); if(!s.base) { cout<<"overflow"<<endl; return; } s.top=s.base; s.stackSize=Stack_Init_Size; } void GetTop(Stack s,string &str) { if(s.base==s.top) { return; } str=*(s.top-1); } void Push(Stack &s,string str) { if(s.top-s.base>=s.stackSize) { s.base=(string *)realloc(s.base,(s.stackSize+StackIncrement)*sizeof(string)); if(!s.base) { return; } s.top=s.base+s.stackSize; s.stackSize=StackIncrement; } *s.top++=str; } void Pop(Stack &s,string &str) { if(s.base==s.top) { return; } str=*--s.top; }