主题:新人求助,关于队列的问题
我初始化一个顺序队列用的一个数组,然后设定了一个头,一个尾,都是 int 型的,入队是把尾++,出队是把头++,那么出队之后是这个出队的元素我还能访问,这个出队到底是什么意思,有没有大佬详细解释一下,部分代码如下:
int create_Q(SqQueue& Q,int e)//创建顺序队列
{
Q.data[Q.rear] = e;
Q.rear++;
if (Q.rear > MAXSIZE)//MAXSIZE=6
{
return 0;
}
else
{
cout << "插入成功" << endl;
return ok;
}
}
int deleteQ(SqQueue& Q,int &e)//出队
{
if (Q.front == Q.rear)
{
cout << "队列已空" << endl;
return 0;
}
else
{
e = Q.data[Q.front];
Q.front++;
cout << e << "已经出队" << endl;
return 1;
}
}
int main()
{
SqQueue Q;
int i;
int res = Init_Q(Q);//初始化队列
if (res)
{
cout << "队列初始化成功" << endl;
}
else
{
cout << "未初始化" << endl;
}
int res1=create_Q(Q,0);
res1 = create_Q(Q, 1);
res1 = create_Q(Q, 2);
res1 = create_Q(Q, 3);
res1 = create_Q(Q, 4);
res1 = create_Q(Q, 5);
int e;
int res2 = deleteQ(Q, e);
res2 = deleteQ(Q, e);
res2 = deleteQ(Q, e);
res2 = deleteQ(Q, e);
res2 = deleteQ(Q, e);
res2 = deleteQ(Q, e);
cout << Q.data[1] << endl;
return 0;
}