数据结构 栈的基本操作 请问错在哪了?
#include"stdio.h"#defineStackSize10typedefcharDataType;typedefstruct{DataTypedata[Sta...
#include "stdio.h"
#define StackSize 10
typedef char DataType;
typedef struct
{
DataType data[StackSize];
int top;
}SeqStack;
//初始化
void InitStack( SeqStack *s )
{
s->top = -1;
}
//判满
int StackEmpty( SeqStack *s )
{
return s->top == -1;
}
//判空
int StackFull( SeqStack *s )
{
return s->top == StackSize - 1;
}
//元素入栈
int push( SeqStack *s, DataType item )
{
if(StackFull(s))
{
printf("满");
return 0;
}
else
{
s->top = s->top + 1; //栈顶下标加一
s->data [s->top ] = item; //元素入栈
return 1;
}
}
//出栈
int Pop( SeqStack *s, DataType item)
{
if(StackEmpty(s))
{
printf("栈空");
return 0;
}
else
{
item = s->data[s->top ]; //出栈
s->top --; //栈顶减一
return 1;
}
}
void main()
{
SeqStack S;
DataType ch;
int i;
InitStack( &s );
for( i = 0; i < 10; i++ )
{
scanf("%c", &ch);
push( &s, ch );
}
for( i = 0; i < StackSize ; i++)
{
Pop( &s, ch);
printf("%5c" , ch);
}
}
错误:
C:\Users\k59\Desktop\Text1.c(56) : error C2065: 's' : undeclared identifier
C:\Users\k59\Desktop\Text1.c(56) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *'
C:\Users\k59\Desktop\Text1.c(60) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *'
C:\Users\k59\Desktop\Text1.c(64) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *' 展开
#define StackSize 10
typedef char DataType;
typedef struct
{
DataType data[StackSize];
int top;
}SeqStack;
//初始化
void InitStack( SeqStack *s )
{
s->top = -1;
}
//判满
int StackEmpty( SeqStack *s )
{
return s->top == -1;
}
//判空
int StackFull( SeqStack *s )
{
return s->top == StackSize - 1;
}
//元素入栈
int push( SeqStack *s, DataType item )
{
if(StackFull(s))
{
printf("满");
return 0;
}
else
{
s->top = s->top + 1; //栈顶下标加一
s->data [s->top ] = item; //元素入栈
return 1;
}
}
//出栈
int Pop( SeqStack *s, DataType item)
{
if(StackEmpty(s))
{
printf("栈空");
return 0;
}
else
{
item = s->data[s->top ]; //出栈
s->top --; //栈顶减一
return 1;
}
}
void main()
{
SeqStack S;
DataType ch;
int i;
InitStack( &s );
for( i = 0; i < 10; i++ )
{
scanf("%c", &ch);
push( &s, ch );
}
for( i = 0; i < StackSize ; i++)
{
Pop( &s, ch);
printf("%5c" , ch);
}
}
错误:
C:\Users\k59\Desktop\Text1.c(56) : error C2065: 's' : undeclared identifier
C:\Users\k59\Desktop\Text1.c(56) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *'
C:\Users\k59\Desktop\Text1.c(60) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *'
C:\Users\k59\Desktop\Text1.c(64) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct SeqStack *' 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询