#include <iostream>
using namespace std;
#define MaxSize 10
typedef struct{
int data[MaxSize];
int front,rear;
}SqQueue;
void InitSqQueue(SqQueue &Q){
Q.front=Q.rear=0;
}
bool EmptySqQueue(SqQueue Q){
return (Q.front==Q.rear);
}
bool FullSqQueue(SqQueue Q){
return ((Q.rear+1)%MaxSize==Q.front);
}
bool EnQueue(SqQueue &Q, int x){
if((Q.rear+1)%MaxSize==Q.front)
return false;
Q.data[Q.rear]=x;
Q.rear=(Q.rear+1)%MaxSize;
return true;
}
bool DeQueue(SqQueue &Q, int &x){
if(Q.rear==Q.front)
return false;
x=Q.data[Q.front];
Q.front=(Q.front+1)%MaxSize;
return true;
}
bool GetHead(SqQueue Q,int &x){
if(Q.front==Q.rear)
return false;
x=Q.data[Q.front];
return true;
}
typedef struct LinkNode{
int data;
struct LinkNode *next;
}LinkNode;
typedef struct{
LinkNode *front,*rear;
}LinkQueue;
void InitLQueue(LinkQueue &Q){
Q.front=Q.rear=(LinkNode *)malloc(sizeof(LinkNode));
Q.front->next=NULL;
}
bool EmptyLQueue(LinkQueue Q){
return (Q.front==Q.rear);
}
void InitQueue_NoHeadNode(LinkQueue &Q){
Q.front=Q.rear=NULL;
}
bool EmptyQueue_NoHeadNode(LinkQueue Q){
return (Q.front==NULL);
}
bool EnQueue(LinkQueue &Q, int x){
LinkNode *p=(LinkNode *)malloc(sizeof(LinkNode));
if(p==NULL)
return false;
p->data=x;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return true;
}
bool EnQueue_NoHeadNode(LinkQueue &Q, int x){
LinkNode *p=(LinkNode *)malloc(sizeof(LinkNode));
if(p==NULL)
return false;
p->data=x;
p->next=NULL;
if(Q.front==NULL){
Q.front=p;
Q.rear=p;
}else{
Q.rear->next=p;
Q.rear=p;
}
return true;
}
bool DeQueue(LinkQueue &Q,int &x){
if(Q.front==Q.rear)
return false;
LinkNode *p=Q.front->next;
x=p->data;
Q.front->next=p->next;
if(p==Q.rear)
Q.rear=Q.front;
free(p);
return true;
}
bool DeQueue_NoHeadNode(LinkQueue &Q, int &x){
if(Q.front==NULL)
return false;
LinkNode *p=Q.front;
x=p->data;
Q.front=p->next;
if(Q.rear==p){
Q.front=NULL;
Q.rear=NULL;
}
free(p);
return true;
}
int main()
{
return 0;
}
|