标签:
#define MaxSize 10 typedef struct Node{ ElementType *Array; int front; int rear; } *Queue; Queue CreateQueue( int MaxSize ) { Queue PtrQ; PtrQ = malloc(sizeof(struct Node )); if(PtrQ == NULL) printf("out of space "); PtrQ->Array = malloc(sizeof( ElementType ) * MaxSize ); if(PtrQ == NULL ) printf("out of space "); PtrQ->front = 0; PtrQ->rear = 0; return PtrQ; } int IsFull( Queue PtrQ ) { return (rear+1) % MaxSize == front; } void AddQ(ElementType X, Queue PtrQ) { if( IsFull( PtrQ ) ) { printf("队列满"); return; } PtrQ->rear = (Q->rear + 1) % MaxSize; PtrQ->Array[PtrQ->rear] = X; } int IsEmpty(Queue PtrQ ) { return PtrQ->rear == PtrQ->front; } ElementType DeleteQ( Queue PtrQ ) { if( IsEmpty( PtrQ ) ) { printf("队列空"); return; } PtrQ->front = (PtrQ->front + 1) % MaxSize; return PtrQ->Array[PtrQ->front]; }
标签:
原文地址:http://www.cnblogs.com/gabygoole/p/4618377.html