Home > Back-end >  Why x do not show the number in the queue, but shows these puzzling Numbers?
Why x do not show the number in the queue, but shows these puzzling Numbers?

Time:11-10


#include
# define maxnum 100
using namespace std;

Typedef struct {
The int data [maxnum];
Int the front;
Int rear;
} sqQueue;

/*
Team empty status: qu. Rear==qu. The front;
Team full state: (qu. The rear + 1) % maxnum==qu. The front;
Into the team operation: qu. Rear=(qu. The rear + 1) % maxnum; Qu. Data [qu. Rear]=x;
The team operation: qu. Front=(qu. The front + 1) % maxnum; X=qu. Data [qu. Front];
*/

//initialize
Void initQueue (sqQueue& Qu)
{
Qu. The front=qu. The rear;
}
//determine team empty
Int isQueueEmpty (sqQueue qu)
{
If (qu. Front==qu. Rear)
{
Cout & lt; <"Team" empty & lt; return 1;
}
The else
{
Cout & lt; <"Team is not empty" & lt; return 0;
}
}
//into the team
Int the enQueue (sqQueue& Qu, int x)
{
If ((qu. The rear + 1) % maxnum==qu. The front)
{
Cout<& lt;" Team full to team "& lt; return 0;
}
Qu. Rear=(qu. The rear + 1) % maxnum;
Qu. Data [qu. Rear]=x;
return 1;
}
//the team
Int to deQueue (sqQueue& Qu, int& X)
{
If (qu. Rear==qu. Front) {
Cout & lt; <"Teams empty and not a" & lt; return 0;
}
Qu. Front=(qu. The front + 1) % maxnum;
X=qu. Data [qu. Front];
return 1;
}
Int main ()
{
int x;
SqQueue q;
InitQueue (q);
IsQueueEmpty (q);
The enQueue (q), 1);
The enQueue (q), 2);
IsQueueEmpty (q);
DeQueue (q), x);
Cout & lt; DeQueue (q), x);
Cout & lt; IsQueueEmpty (q);
return 0;
}
  • Related