队列基本操作的C语言实现(附源代码已测试)

这篇博客展示了如何使用C语言实现链队列的基本操作,包括初始化、入队、出队、获取队头元素以及计算队列长度。源代码已经过测试,适合学习数据结构的读者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/////////////////////////////////
//      作者:happy_fun        //
//  队列基本操作的C语言实现 //
//   时间:2011年11月25号   //
//   未经作者允许不得转载!  //
/////////////////////////////////
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct QElemType
{
	int data;
	struct QElemType *next;
}elemtype;
typedef struct QNode
{
	elemtype *front;
	elemtype *rear;
}LinkQueue;//链队列

void main()
{
	int InitType(LinkQueue *Q);
	int EnQueue(LinkQueue *Q);
	int QueueLength(LinkQueue *Q);
	elemtype GetHead(LinkQueue *Q);
	int DelQueue(LinkQueue *Q);

	LinkQueue Q;
	if(InitType(&Q)==1)
		printf("构造空对了成功!\n\n");
	if(EnQueue(&Q)==1)
		printf("插入元素到队列成功!\n\n");
	printf("该队列元素个数为:%d\n\n",QueueLength(&Q));
	printf("该队列的首元素为:%d\n\n",GetHead(&Q));
	if(DelQueue(&Q)==1)
		printf("删除队头元素成功!\n\n");
}

int InitType(LinkQueue *Q)
{
	Q->front=(elemtype *)malloc(sizeof(elemtype));
	Q->rear=Q->front;
	if(!Q->front)
	{
		printf("构造空队列失败!\n");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值