求大神帮我把每一个句子解释一下,每一个句子,

问题描述:

求大神帮我把每一个句子解释一下,每一个句子,
#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);
}
1个回答 分类:综合 2014-11-30

问题解答:

我来补答
#include //头文件应该不用我介绍了吧如果实在不知道真的需要去好好看书#include #include #include #include #define STACK_IN99v_SIZE 100 //初始化栈值的大小#define STACKINCREMENT 10//如果栈满的话分配多余空间的大小struct SqStack //栈的结构体包含一个栈底的指针BASE和栈顶的指针TOP 还有用来记录栈的存储空间大小的整型变量{ \x05char *base; \x05char *top; \x05int stacksize; }; void InitStack(SqStack &S)//初始化栈{\x05S.base=(char*)malloc(STACK_IN99v_SIZE *sizeof(char));/*为栈分配存储空间大小就是STACK_IN99v_SIZE乘以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)//用e来代替栈顶数据的函数{\x05if (S.top==S.base)//栈满返回false也就是错误出口\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)//判断栈是否为空的函数正确返回true错误反之{\x05if (S.top==S.base)\x05\x05return true; \x05return false;}void main(){\x05char ch,e; \x05SqStack S,D; \x05//初始化2个栈 \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))//栈非空的话进行入栈操作和pop操作\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);//销毁栈}/*你的分确实给的很少而且这个数据结构不可能每一句都看不懂 最好是你那里看不懂再出指明来问那样我们解答的人也会多 最后给一句忠告如果真的要学好的话多看看书还是很重要的基础对于学习计算机来说还是很重要的.如果有错还望能指出*/
 
 
展开全文阅读
剩余:2000
上一页:hfftbjhg