大佬们 帮忙看看栈和队列的类型定义问题
我栈类型定义是
typedef struct stacknote
{
char data;
struct stacknote *next;
}stacknote,*Linkstackptr;
typedef struct node
{
int count;
Linkstackptr top;
}Linkstack;
在置空栈函数中的动态分配内存格式
void Initstack(Linkstack* s)
{
s = (Linkstack*)malloc(sizeof(Linkstack));
if (*s == NULL)
{
return;
}
else
{
s->top = NULL;
}
}
这是队列的类型定义和动态分配内存格式
typedef struct queuenote
{
int data;
struct queuenote *next;
}queuenote,*Linkqueueptr;
typedef struct
{
Linkqueueptr front,rear;
}Linkqueue;
置空
int Initqueue(Linkqueue *p)
{
p->front=p->rear=(Linkqueueptr)malloc(sizeof(queuenote));
if(!p->front)
{
return 0;
}
p->front->next=p->rear->next=NULL;
return 1;
}
为什么这两个不一样 我在适应了栈的格式后,把他套在队列上 结果不对这是为什么求大佬解析一下。
最后还有一个小问题
void print(Linkqueue q)
{
while(q.front!=q.rear)
{
q.front=q.front->next; //注意front指向头结点非第一个结点 故先指向下一个
printf("%d\n",q.front->data);
}
}在打印队列的时候为啥是q.front而不是q->front
这两个有啥差别