/////////////////////////////////
// 作者: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");
队列基本操作的C语言实现(附源代码已测试)
最新推荐文章于 2024-05-12 19:01:24 发布
这篇博客展示了如何使用C语言实现链队列的基本操作,包括初始化、入队、出队、获取队头元素以及计算队列长度。源代码已经过测试,适合学习数据结构的读者参考。

最低0.47元/天 解锁文章
1710

被折叠的 条评论
为什么被折叠?



