Create 链队初始化(带头结点).c

This commit is contained in:
ViolentAyang
2022-03-21 13:59:18 +08:00
committed by GitHub
parent 59a827c529
commit 428daa1d09

View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define MaxSize 10
typedef struct LinkNode{
int data;
struct LinkNode *next;
}LinkNode;
typedef struct LinkQueue{
LinkNode *front,*rear;
}LinkQueue;
//初始化队列(带头结点)
void InitQueue(LinkQueue *Q){
//初始时 front、rear都指向头结点
Q->front = Q->rear = (LinkNode*)malloc(sizeof(LinkNode));
Q->front->next = NULL;
}
//判断队列是否为空
bool IsEmpty(LinkQueue Q){
if(Q.front==Q.rear){
return true;
}else{
return false;
}
}
int main(){
LinkQueue Q;
InitQueue(&Q);
printf("队列是否为空:%d",IsEmpty(Q));
return 0;
}