#include<stdio.h>
#include<malloc.h>
#define QElemtype int
#define status int
typedef struct QNode {
QElemtype data;
struct QNode* next;
}QNode,*QueuePtr;
typedef struct {
QueuePtr front;
QueuePtr rear;
}LinkQueue;
status InitQueue(LinkQueue* Q) {
Q->front = Q->rear = (QNode*)malloc(sizeof(QNode));
Q->front->next = NULL;
return 1;
}
status EnQueue(LinkQueue* Q, int e) {
QNode* p = (QNode*)malloc(sizeof(QNode));
p->next = NULL;
p->data = e;
Q->rear->next = p;
}
status InQueue(LinkQueue* Q, int* e) {
QNode* p = (QNode*)malloc(sizeof(QNode));
p = Q->front->next;
e = p->data;
Q->front->next = p->next;
free(p);
}
status ReadLinkQueue(LinkQueue* Q) {
return Q->front->data;
}
int main()
{
LinkQueue Q;
InitQueue(&Q);
EnQueue(&Q, 1);
printf("%d", ReadLinkQueue(&Q));
}
为什么输出值是随机值而不是我想要的数字1呢?