链表队的创立与遇到的问题。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39642794/article/details/81606793

typedef struct Node

{

int data;

struct Node *next;

}Qnode;

typedef struct

{

Qnode *front,*rear;

}Linkqueue;

Linkqueue *Q;

头尾指针是属于一个结构体,相当于一个结构体有这两个值。

开辟内存:

Q=(Linkqueue *)malloc(sizeof(Qnode));

Q->front=Q->rear= (Qnode *) malloc(sizeof(Qnode));

Q->front->next=Q->rear->next=NULL;

不能写成Q->front=Q->rear=NULL在上一篇博客(p->next=NULL和p=NULL)已经讲了为什么不可以 这样属于无效指针;

猜你喜欢

转载自blog.csdn.net/qq_39642794/article/details/81606793