/*
* linkqueue.c
*
* Created on: 2018年11月22日
* Author: Jinjin
*/
#include<stdio.h>
#include<malloc.h>
//链队列的表示和实现
//链队列的类型定义
typedef int ElemType;
typedef struct node{
ElemType data;
struct node *next;
}qlink;
typedef struct{
qlink *front;
qlink *rear;
}linkqueue;
//初始化操作
void initqueue(linkqueue *LQ){
LQ->front=LQ->rear=(qlink *)malloc(sizeof(qlink));
//需要同时给队头指针和队尾指针申请空间
LQ->front->next=NULL;
}
//求队列长度操作
int getlen(linkqueue *LQ){
int i;
qlink *p;
p=LQ->front->next;
i=0;p=LQ->front->next;
while(p!=NULL){
i++;
p=p->next;
}
return i;
}
//判队空操作
int emptyqueue(linkqueue *LQ){
if(LQ->front==LQ->rear)return 1;
else return 0;
}
//取队头元素
int getfront(linkqueue *LQ,ElemType *e){
if(LQ->front==LQ->rear)return 0;//队空,返回0
*e=LQ->front->next->data;
return 1;
}
//入队列操作
int enqueue(linkqueue *LQ,ElemType x){
qlink *p
链队列的表示和实现(C语言)
最新推荐文章于 2022-05-17 20:10:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)