问题描述:
求大神帮我把每一个句子解释一下,每一个句子,
#include
#include
#include
#include
#include
#define STACK_IN99v_SIZE 100
#define STACKINCREMENT 10
struct SqStack
{
\x05char *base;
\x05char *top;
\x05int stacksize;
};
void InitStack(SqStack &S)
{
\x05S.base=(char*)malloc(STACK_IN99v_SIZE *sizeof(char));
\x05if S.base)
\x05\x05exit(1);
\x05S.top=S.base;
\x05S.stacksize=STACK_IN99v_SIZE;
}
void push(SqStack &S,char e)
{
\x05if(S.top-S.base>=S.stacksize)
\x05{
\x05\x05S.base=(char*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(char));
\x05\x05if S.base)
\x05\x05\x05exit(1);
\x05\x05\x05S.top=S.base+S.stacksize;
\x05\x05\x05S.stacksize+=STACKINCREMENT;
\x05\x05\x05}
\x05*S.top++=e;
}
char pop(SqStack &S,char &e)
{
\x05if (S.top==S.base)
\x05\x05 return false;
\x05e=*--S.top;
\x05return e;
}
void ClearStack(SqStack &S)
{
\x05S.top=S.base;
}
void DestroyStack(SqStack &S)
{
\x05free(S.base);
\x05S.top=S.base;
}
bool StackEmpty(SqStack &S)
{
\x05if (S.top==S.base)
\x05\x05return true;
\x05return false;
}
void main()
{
\x05char ch,e;
\x05SqStack S,D;
\x05InitStack(S);
\x05InitStack(D);
\x05ch=getchar();
\x05while (ch!=EOF)
\x05{
\x05\x05while(ch!=EOF&&ch!='\n')
\x05\x05{
\x05\x05\x05switch(ch)
\x05\x05\x05{
\x05\x05\x05\x05 case'#':pop(S,e);break;
\x05\x05\x05\x05\x05 case'@':ClearStack(S);break;
\x05\x05\x05\x05\x05 default:push(S,ch);break;
\x05\x05\x05}
\x05\x05\x05ch=getchar();
\x05\x05}
\x05\x05while StackEmpty(S))
\x05\x05{
\x05\x05\x05e=pop(S,e);
\x05\x05\x05push (D,e);
\x05\x05}
\x05\x05while StackEmpty(D))
\x05\x05{
\x05\x05\x05 e=pop(D,e);
\x05\x05\x05 printf("%c",e);
\x05\x05}
\x05\x05 ClearStack(S);
\x05\x05 if(ch!=EOF)ch=getchar();
\x05\x05 }
\x05DestroyStack(S);
}
#include
#include
#include
#include
#include
#define STACK_IN99v_SIZE 100
#define STACKINCREMENT 10
struct SqStack
{
\x05char *base;
\x05char *top;
\x05int stacksize;
};
void InitStack(SqStack &S)
{
\x05S.base=(char*)malloc(STACK_IN99v_SIZE *sizeof(char));
\x05if S.base)
\x05\x05exit(1);
\x05S.top=S.base;
\x05S.stacksize=STACK_IN99v_SIZE;
}
void push(SqStack &S,char e)
{
\x05if(S.top-S.base>=S.stacksize)
\x05{
\x05\x05S.base=(char*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(char));
\x05\x05if S.base)
\x05\x05\x05exit(1);
\x05\x05\x05S.top=S.base+S.stacksize;
\x05\x05\x05S.stacksize+=STACKINCREMENT;
\x05\x05\x05}
\x05*S.top++=e;
}
char pop(SqStack &S,char &e)
{
\x05if (S.top==S.base)
\x05\x05 return false;
\x05e=*--S.top;
\x05return e;
}
void ClearStack(SqStack &S)
{
\x05S.top=S.base;
}
void DestroyStack(SqStack &S)
{
\x05free(S.base);
\x05S.top=S.base;
}
bool StackEmpty(SqStack &S)
{
\x05if (S.top==S.base)
\x05\x05return true;
\x05return false;
}
void main()
{
\x05char ch,e;
\x05SqStack S,D;
\x05InitStack(S);
\x05InitStack(D);
\x05ch=getchar();
\x05while (ch!=EOF)
\x05{
\x05\x05while(ch!=EOF&&ch!='\n')
\x05\x05{
\x05\x05\x05switch(ch)
\x05\x05\x05{
\x05\x05\x05\x05 case'#':pop(S,e);break;
\x05\x05\x05\x05\x05 case'@':ClearStack(S);break;
\x05\x05\x05\x05\x05 default:push(S,ch);break;
\x05\x05\x05}
\x05\x05\x05ch=getchar();
\x05\x05}
\x05\x05while StackEmpty(S))
\x05\x05{
\x05\x05\x05e=pop(S,e);
\x05\x05\x05push (D,e);
\x05\x05}
\x05\x05while StackEmpty(D))
\x05\x05{
\x05\x05\x05 e=pop(D,e);
\x05\x05\x05 printf("%c",e);
\x05\x05}
\x05\x05 ClearStack(S);
\x05\x05 if(ch!=EOF)ch=getchar();
\x05\x05 }
\x05DestroyStack(S);
}
问题解答:
我来补答展开全文阅读