链队列的结构及其操作

本文详细介绍了链队列的结构,包括如何初始化、入队、出队、判断队列是否为空以及打印队列内容。通过示例代码展示了链队列的操作过程,如向队列中插入1、2、3三个元素,然后依次出队,最后输出队列状态。
摘要由CSDN通过智能技术生成
/**
 *
 *	作者:LinX   2017-6-16-上午  
 *
 *	内容:链队列的结构及其应用 
 *
 *	看严蔚敏教材上的图解,就很清晰 
 */

#include <stdio.h> 
#include <stdlib.h>

typedef int ElemType;

typedef struct QNode
{
	
	ElemType data;
	
	struct QNode *next;
	
}QNode,*QueuePtr;

typedef struct
{
	
	QueuePtr front;
	
	QueuePtr rear;
	
}LinkQueue;

/*基本操作*/

LinkQueue* initQueue();							//初始化链队列
	
void EnQue(LinkQueue *Q,ElemType e);			//入队

ElemType DeQue(LinkQueue *Q);					//出队

int isEmpty(LinkQueue *Q);						//判空

void printQue(LinkQueue *Q);					//输出队列 

int main()
{
	
	LinkQueue *Q=initQueue();
	
	EnQue(Q,1);
	
	EnQue(Q,2);
	
	EnQue(Q,3);
	
	printQue(Q);
	
	DeQue(Q);
	
	DeQue(Q);
	
	DeQue(Q);
	
	printQue(Q);
	
	DeQue(Q);
	
	return 0;
	
}

/*初始化链队列*/
LinkQueue* initQueue()
{
	
	LinkQueue *Q=(LinkQueue*)malloc(sizeof(LinkQueue));
	
	//两个指针同时指向一个节点 
	Q->front=(QueuePtr *)malloc(sizeof(QueuePtr));
	
	Q->rear=Q->front;
	
	Q->front->next&
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值