数据结构的停车场问题
#include<stdio.h>typedef struct
{
int num[10];
int entertime[10];
int top;
}seqstack;
void initstack(seqstack *s)
{
s->top=0;
}
void push(seqstack *s,int x,int y)
{
s->num [s->top ]=x;
s->entertime[s->top ]=y;
s->top++;
}
void pop(seqstack *s,int *x,int *y)
{
s->top--;
*x=s->num[s->top];
*y=s->entertime[s->top];
}
int stackempty(seqstack s)
{
if(s.top==0) return 1;
else return 0;
}
main()
{
seqstack *s1,*s2;
int num,time;
initstack(s1);
initstack(s2);
push(s1,1,0);
push(s1,2,3);
push(s1,3,6);
push(s1,4,9);
push(s1,5,12);
while(!stackempty (*s1))
{
pop(s1,&num,&time);
push(s2,num,time);
printf("number=%d,time=%d:\n",num,time);
}
}
谁能帮忙解释一下结构体部分的意思~
typedef struct
{
int num[10];
int entertime[10];
int top;
}seqstack;
还有几个函数
void push(seqstack *s,int x,int y)和void pop(seqstack *s,int *x,int *y)的区别~
尤其是int x,int y和int *x,int *y的区别~ 没人帮忙?[tk01] [tk13] #include<stdio.h>
#include<malloc.h>
typedef struct
{
int num[10];
int entertime[10];
int top;
}seqstack;
void initstack(seqstack *s)
{
s->top=0;
}
void push(seqstack *s,int x,int y)
{
s->num [s->top ]=x;
s->entertime[s->top ]=y;
s->top++;
}
void pop(seqstack *s,int *x,int *y)
{
s->top--;
*x=s->num[s->top];
*y=s->entertime[s->top];
}
int stackempty(seqstack s)
{
if(s.top==0) return 1;
else return 0;
}
int main()
{
seqstack *s1,*s2;
s1=(seqstack*)malloc(sizeof(seqstack));
s2=(seqstack*)malloc(sizeof(seqstack));
int num,time;
initstack(s1);
initstack(s2);
push(s1,1,0);
push(s1,2,3);
push(s1,3,6);
push(s1,4,9);
push(s1,5,12);
while(!stackempty (*s1))
{
pop(s1,&num,&time);
push(s2,num,time);
printf("number=%d,time=%d:\n",num,time);
}
return 0;
}
这样才是对的..而且第二个栈没必要...只要记住FIFO就好了 g:\et\c\stack\stack.c(35) : error C2143: syntax error : missing ';' before 'type'
g:\et\c\stack\stack.c(45) : error C2065: 'num' : undeclared identifier
g:\et\c\stack\stack.c(45) : error C2065: 'time' : undeclared identifier
有这三个错误
不知道怎么调试正确~
望LS的大哥再帮一下忙 有问题的还挂在上面!!!
页:
[1]
