帮我调试一下,初始化函数怎么不对

来源:百度知道 编辑:UC知道 时间:2024/05/20 11:56:32
#include<iostream.h>
#include<stdlib.h>
const int QueueMaxSize=8;
typedef int ElemType;
struct Queue{
ElemType queue[QueueMaxSize];
int front ,rear;
};

void InitQueue(Queue&Q)
{
Q.front =Q.rear==0 ;
}
void QInsert(Queue&Q,const ElemType& item)
{
int k=(Q.rear +1)%QueueMaxSize;//求出队列的下一个位置
if (k==Q.front )
{
cerr<<"Queue overflow"<<endl;
exit(1);
}
Q.rear =k;
Q.queue [k]=item;
}
int QueueEmpty(Queue&Q)
{
return Q.front =Q.rear ;
}
int QueueFull(Queue&Q)
{
return (Q.rear +1)%QueueMaxSize==Q.front ;
}
ElemType QDelete(Queue&Q)
{
if (Q.front ==Q.rear )
{
cerr<<"Queue is empty"<<endl;
exit(1);
}
Q.front =(Q.front +1)%QueueMaxSize;
return Q.queue [Q.front ];
}
void CoutOut(Queue&Q)
{
while(Q.fro

#include<iostream.h>
#include<stdlib.h>
const int QueueMaxSize=8;
typedef int ElemType;
struct Queue{
ElemType queue[QueueMaxSize];
int front ,rear;
};

void InitQueue(Queue&Q)
{
Q.front =Q.rear=0 ; //--------------呵呵,你粗心了,多写了一个'='---------------------
}

void QInsert(Queue&Q,const ElemType& item)
{
int k=(Q.rear +1)%QueueMaxSize;//求出队列的下一个位置
if (k==Q.front )
{
cerr<<"Queue overflow"<<endl;
exit(1);
}
Q.rear =k;
Q.queue [k]=item;
}

int QueueEmpty(Queue&Q)
{
return Q.front =Q.rear ;
}
int QueueFull(Queue&Q)
{
return (Q.rear +1)%QueueMaxSize==Q.front ;
}
ElemType QDelete(Queue&Q)
{
if (Q.front ==Q.rear )
{
cerr<<"Queue is empty"<<endl;
exit(1);
}
Q.front =(Q.front +1)%QueueMaxSize;
return Q