Queue的数组定义
#define MaxSize 100
typedef struct {
ElementTyPe Data[MaxSize];
int front;
int rear;
}Queue;
void AddQ(Queue *PtrQ,ElementTyPe item){
if((PtrQ->rear+1) % MaxSize == PtrQ->front){
printf("队列满");
return;
}
PtrQ->rear = (PtrQ->rear + 1) % MaxSize;
PtrQ->Data[PtrQ->rear] = item;
}
ElementTyPe DeleteQ(Queue *PtrQ){
if(PtrQ->front == PtrQ-rear){
printf("队列空");
return ERROR;
}else{
PtrQ->front = (PtrQ->front + 1)% MaxSize;
return PtrQ->Data[PtrQ->front];
}
}
Queue的链表定义
typedef struct Node{
ElementTyPe Data;
struct Node *Next;
}QNode;
typedef struct{
QNode *front;
QNode *rear;
}LinkQueue;
LinkQueue *PtrQ;
ElementTyPe DeleteQ( LinkQueue *PtrQ){
QNode *FrontCell;
ElementTyPe FrontElem;
if(PtrQ->front == NULL){
printf("队列空");
return ERROR;
}
FrontCell = PtrQ->front;
if(PtrQ->front == PtrQ->rear)
PtrQ->front = PtrQ->rear = NULL;
else {
PtrQ->front = PtrQ->front->Next;
}
FrontElem = FrontCell->Data;
free(FrontCell);
return FrontElem;
}