请高手解释下q.top==q.bottom与q->top==q->bottom的区别
#include<stdio.h>#include<malloc.h>
#define Max 20
#define Increase 10
typedef int datatype;
typedef struct stack
{datatype *top;
datatype *bottom;
int increase;
}stack,*pstack;
void Initstack(pstack q);
void push(pstack q,datatype m);
datatype pop(pstack q);
main()
{stack head;
int i;
Initstack(&head);
for(i=0;i<50;i++)
push(&head,i);
while(head.top != head.bottom)
printf("%d\t",pop(&head));
}
void Initstack(pstack q)
{q->bottom=(datatype *)malloc(Max*sizeof(datatype));
if(!q->bottom)
{printf("stack creat failure!\n");
exit(1);
}
q->top=q->bottom;
q->increase=Max;
}
void push(pstack q,datatype m)
{if(q->top-q->bottom>=q->increase)
{q->bottom=(datatype*)realloc(q->bottom,(q->increase+Increase)*sizeof(datatype));
if(!q->bottom)
{printf("stack creat failure!\n");
exit(1);
}
q->top=q->bottom+q->increase;
q->increase+=Increase;
}
*q->top++=m;
}
datatype pop(pstack q)
{if(q.top==q.bottom) //为什么不能写成if(q->top==Q->bottom)
{printf("stack is empty!\n");
exit(1);
}
return *--q->top;
}
[ 本帖最后由 jack222 于 2011-6-24 21:27 编辑 ]