#includestdio.h
#includeconio.h
#includemalloc.h
#define MaxSize 100
#define NULL 0
typedef struct
{
int data[MaxSize];
int top;
}SeqStack;
SeqStack *InitStack(void)
/*初始化栈*/
{
SeqStack *s;
s=(SeqStack *)malloc(sizeof(SeqStack));
if(!s)
{
printf(\"空间不足!\");
return 0;
}
else
{
s-top=-1;
return s;
}
}
int IsEmpty(SeqStack *s)
/*判断栈是否为空*/
{
if(s-top==-1) return 1;
else return 0;
}
int IsFull(SeqStack *s)
/*判断栈是否为满*/
{
return(s-top==MaxSize-1);
}
void Push(SeqStack *s,int n,int r)
/*入栈*/
{
while(n!=0)
{
if(!IsFull(s))
{
s-top;
s-data[s-top]=n%r;
n=n/r;
}
else
{
printf(\"栈满\");
return;
}
}
}
void Pop(SeqStack *s)
/*出栈*/
{
while(!IsEmpty(s))
{
if(s-top!=-1)
{
if(s-data[s-top]10) printf(\"%d\",s-data[s-top]);
else printf(\"%c\",\'A\' s-data[s-top]-10);
s-top--;
}
else
{
printf(\"栈空\");
return;
}
}
}
int main(int argc,char *argv[])
{
int n,r;
SeqStack *s;
s=InitStack();
printf(\"n,r:\");
scanf(\"%d,%d\",
Push(s,n,r),Pop(s);
getch();
return 0;
}
这个程序看不懂,谁能帮我解释拷贝 |