标签:type 顺序存储 实现 turn struct include return pre const
#include <stdio.h> #include <stdlib.h> #define ElementType int const int MAXSIZE = 10; typedef struct QNode *Queue; typedef struct QNode{ ElementType Data[MAXSIZE]; int rear; int front; }; void InitQueue(Queue &Q){ Q = (Queue)malloc(sizeof(struct QNode)); Q->rear = Q->front = 0; } bool Is_Empty_Queue(Queue Q){ return Q->front == Q->rear; } bool Is_Full_Queue(Queue Q){ return ((Q->rear + 1)% MAXSIZE == Q->front); } bool AddQ(Queue &Q, ElementType X){ if(Is_Full_Queue(Q)){ printf("队列满\n"); return 0; } Q->rear =(Q->rear+1) % MAXSIZE; Q->Data[Q->rear] = X; } ElementType DelQ(Queue &Q){ if(Is_Empty_Queue(Q)){ printf("队列为空\n"); }else{ Q->front = (Q->front+1)%MAXSIZE; return Q->Data[Q->front]; } } int main(){ Queue Q; InitQueue(Q); for(int i = 0;i<15;i++) AddQ(Q,i); for(int i = 0;i< 9;i++) printf("%d\n",DelQ(Q)); return 0; }
标签:type 顺序存储 实现 turn struct include return pre const
原文地址:http://www.cnblogs.com/zangkuo/p/6143419.html