ADT Queue is
operations
Queue createEmptyQueue(void)
int isEmptyQueue(Queue qu)
void enQueue(Queue qu, DataType x)
void deQueue(Queue qu)
DataType frontQueue( Queue qu )
end ADT Queue
//顺序表示
struct SeqQueue{
int MAXNUM;
int f,r;
DataType * q;
};
typedef struct SeqQueue * PSeqQueue;
PSeqQueue createEmptyQueue(int m)
{
PSeqQueue queue = (PSeqQueue)malloc(sizeof(struct SeqQueue));
queue->f = queue->r = 0;
queue->MAXNUM = m;
queue->p = NULL;
}
int isEmptyQueue_seq(PSeqQueue paqu)
{
return (paqu->f == paqu->r);
}
void enQueue_seq(PSeqQueue paqu, DataType x)
{
if((paqu->r+1) % MAXNUM == paqu->f)
printf("Full queue!\n");
else
{
paqu->q[paqu->r] = x;
paqu->r = (paqu->r+1) % MAXNUM ;
}
}
void deQueue_seq(PSeqQueue paqu)
{
if(paqu->f == paqu->r)
printf("Empty queue!\n");
else
paqu->f = (paqu->f+1) % MAXNUM;
}
DataType frontQueue_seq(PSeqQueue paqu)
{
if(paqu->f == paqu->r)
printf("Empty Queue!\n");
else
return (paqu->q[paqu->f]);
}
//—————————————————————————连接表示——————————————————————————————
struct Node;
typedef struct Node * PNode;
struct Node{
DataType info;
PNode link;
};
struct LinkQueue{
PNode f;
PNode r;
};
typedef struct LinkQueue *PLinkQueue;
PLinkQueue createEmptyQueue_link(void)
{
PLinkQueue Plqu;
Plqu = (PLinkQueue)malloc(sizeof(struct LinkQueue));
if(Plqu != NULL)
{
plqu->f = NULL;
plqu->r = NULL;
}
else
printf("OUT of space!\n");
return plqu;
}
int isEmptyQueue_link(PLinkQueue plqu)
{
return (plqu->f = NULL);
}
void enQueue_link(PLinkQueue plqu, DataType x)
{
PNode p;
p = (PNode)malloc(sizeof(struct Node));
if(p == NULL)
print("Out of space!\n");
else{
p->info = x;
p->link = NULL;
if(plqu->f == NULL)
plqu->f = p;
else
plqu->r->link = p;
plqu->r = p;
}
}
void deQueue_link(PLinkQueue Plqu)
{
PNode p;
if(plqu->f == NULL)
printf("Empty queue!\n");
else{
p = plqu->f;
plqu->f = p->link;
free(p);
}
}
DataType frontQueue_link(PLinkQueue plqu)
{
if(plqu->f == NULL)
{
printf("Empty queue!\n");
}
else
return(plqu->f->info);
}