标签:stack printf play scanf pop als i+1 main size
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAXSIZE 1000
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALS 0
typedef int SElemType;
typedef int Status;
typedef struct
{
SElemType data[MAXSIZE];
int top;
}SqStack;
Status Push(SqStack *S,SElemType e);
Status Pop(SqStack *S,SElemType *e);
int main()
{
SqStack s;
s.top=0;
int i,num;
scanf("%d",&(s.top));
for(i=0;i<=s.top;i++)
{
s.data[i]=i+1;
}
Push(&s,222);
for(i=0;i<=s.top;i++)
{
printf("%d ",s.data[i]);
}
Pop(&s,&num);
printf("\n%d",num);
return 0;
}
Status Push(SqStack *S,SElemType e)
{
if(S->top==MAXSIZE-1)
return ERROR;
S->top++;
S->data[S->top]=e;
return OK;
}
Status Pop(SqStack *S,SElemType *e)
{
if(S->top==-1)
return ERROR;
*e=S->data[S->top];
S->top--;
return OK;
}
实战BUG:
1.把S->top写成top了,Codeblocks里只说了有两个ERROR但没指出来,看了两遍才看出来。。
标签:stack printf play scanf pop als i+1 main size
原文地址:http://www.cnblogs.com/LuRenJiang/p/6339821.html