求高手解答 栈的问题不太理解 谢谢啦
#include "stdio.h"#define stacksize 100
int push(int s[],int x,int *ptop)
{
int top;
top=*ptop;
if ( top==stacksize )
{
printf("overflow\n");
return 0;
}
else
{
s[top]=x;
top++;
*ptop=top; //??
return 1; //???
}
}
int pop(int s[],int *py,int *ptop)
{
int top;
top=*ptop;
if (top==0)
{
printf("stack empty\n");
return 0;
}
else
{
--top;
*py=s[top];
*ptop=top; //???
return 1;
}
}
int main()
{
static int s[stacksize];
int top=0,result,y;
int i;
result=push(s,11,&top); //??
result=push(s,22,&top); //??
result=push(s,33,&top); //??
printf("top=%d\n",top);
for (i=0;i<3;i++)
{
if ( (result=pop(s,&y,&top)) == 1 )
printf("top=%d,y=%d\n",top,y);
}
}
打了问号的地方不太理解哦 谢谢