#ifndef _Queue_H
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int QElemType;
typedef int Status;
typedef struct QNode{
QElemType data ;
struct QNode *next ;
}QNode , *QueuePtr;
typedef struct {
QueuePtr front ;
QueuePtr rear ;
}LinkQueue;
//--------基本操作------------
Status InitQueue(LinkQueue &Q);
Status DestroyQueue(LinkQueue &Q);
Status ClearQueue(LinkQueue &Q);
Status QueueEmpty(LinkQueue Q);
int QueueLength(LinkQueue Q);
Status GetHead(LinkQueue Q,QElemType &e);
Status EnQueue(LinkQueue &Q,QElemType e);
Status DeQueue(LinkQueue &Q,QElemType &e);
Status Display(LinkQueue Q);
//Status QueueTraverse(LinkQueue Q,visit());
#endif
实现
#include<stdio.h>
#include<stdlib.h>
#include "Queue.h"
void main(){
LinkQueue Q ;
if(InitQueue(Q)){
printf("初始化成功!\n");
}
for(int i =0;i<5;i++){
EnQueue(Q,i);
}
Display(

本文详细介绍了如何使用链表数据结构来实现队列,包括队列的初始化、元素的入队操作、出队操作以及如何显示队列中的所有元素,帮助理解链表与队列的基本操作。
最低0.47元/天 解锁文章
4968

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



