Home > Back-end >  For a simple circular queue problem, c
For a simple circular queue problem, c

Time:09-22

 # include 
#include
using namespace std;
# define MAXSIZE 10

Typedef string QElemType;
typedef int Status;
Typedef struct QUEUE
{
QElemType * base;//dynamically allocated storage space
Int the front;//the head pointer
Int rear;//the tail pointer
} SqQueue;
The Status InitQueue (SqQueue Q)
{
Q.b ase=(QElemType *) malloc (MAXSIZE * sizeof (QElemType));//initialize the queue
if (! Q.b ase)
{
exit(0);
}
Q.r ear=Q.f ront=0;
return 1;
}

The Status the EnQueue (SqQueue Q, QElemType e)//line
{
If ((Q.r ear + 1) %==10 Q.f ront)//if the team with the
{
cout <"Waiting" & lt; return 0;
}
Q.b ase [Q.r ear]=e;
Q.r ear=(Q.r ear + 1) % 10;
return 1;
}
The Status to Dequeue (SqQueue Q, QElemType & amp; E)//ticket
{
If (Q.f ront==Q.r ear)//team empty
{
cout <"No queues" & lt; return 0;
}
E=Q.b ase [Q.f ront];
Q.f ront=(Q.f ront + 1) % 100;
cout return 1;
}
The Status QueueTraverse (SqQueue Q, QElemType e)//view the queue
{
int i;
I=Q.f ront;
While (I!=Q.r ear)
{
cout I=(I + 1) % 10;
}
cout
return 1;
}

Int main ()
{
cout <"Look at queue line: 1 ticket: 2:3:4" & lt; SqQueue q1={0};
InitQueue (q1);
int a;
String e;
Loop: cin & gt;> a;
If (a==1) {
Cin & gt;> e;
The EnQueue (q1, e);
Goto loop;
}
If (a==2)
{

Dequeue (q1, e);
Goto loop;
}
If (a==3)
{
QueueTraverse (q1, e);
Goto loop;
} the if (a==4); return 0;
}