主题:改的一个栈,一个错误,不解,请大家帮忙
#include <stdio.h>
#include <stdlib.h>
#define size 3
void init(int *top);
void push(int *s,int* top, int element);
int pop(int *s,int *top);
int full(int *top,const int size);//错误在这一行
int empty(int *top);
void main()
{
int top,element;
int stack[size];
init(&top);
while(top != size){
element = rand();
printf("push element %d into stack\n",element);
push(stack,&top,element);
getchar();//press enter to push more
}
printf("stack is full\n");
while(!empty(&top)){
element = pop(stack,&top);
printf("pop element %d from stack\n",element);
getchar();//press enter to pop more
}
printf("stack is empty\n");
getchar();
}
/*
initialize stack pointer
*/
void init(int *top)
{
*top = 0;
}
/*
push an element into stack
precondition: the stack is not full
*/
void push(int *s,int* top, int element)
{
s[(*top)++] = element;
}
/*
pop an element from stack
precondition: stack is not empty
*/
int pop(int *s,int *top)
{
return s[--(*top)];
}
/*
report stack is full nor not
return 1 if stack is full, otherwise return 0
*/
*int full(int *top,const int size)
{
return *top == size ? 1 : 0;
}
/*
report a stack is empty or not
return 1 if the stack is empty, otherwise return 0
*/
int empty(int *top)
{
return *top == 0 ? 1 : 0;
}
运行时出现语句错误:
error :expected ‘;’、‘,’or before numeric constant
不解,请高手指点
#include <stdlib.h>
#define size 3
void init(int *top);
void push(int *s,int* top, int element);
int pop(int *s,int *top);
int full(int *top,const int size);//错误在这一行
int empty(int *top);
void main()
{
int top,element;
int stack[size];
init(&top);
while(top != size){
element = rand();
printf("push element %d into stack\n",element);
push(stack,&top,element);
getchar();//press enter to push more
}
printf("stack is full\n");
while(!empty(&top)){
element = pop(stack,&top);
printf("pop element %d from stack\n",element);
getchar();//press enter to pop more
}
printf("stack is empty\n");
getchar();
}
/*
initialize stack pointer
*/
void init(int *top)
{
*top = 0;
}
/*
push an element into stack
precondition: the stack is not full
*/
void push(int *s,int* top, int element)
{
s[(*top)++] = element;
}
/*
pop an element from stack
precondition: stack is not empty
*/
int pop(int *s,int *top)
{
return s[--(*top)];
}
/*
report stack is full nor not
return 1 if stack is full, otherwise return 0
*/
*int full(int *top,const int size)
{
return *top == size ? 1 : 0;
}
/*
report a stack is empty or not
return 1 if the stack is empty, otherwise return 0
*/
int empty(int *top)
{
return *top == 0 ? 1 : 0;
}
运行时出现语句错误:
error :expected ‘;’、‘,’or before numeric constant
不解,请高手指点