#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(