Home > Back-end >  Lack of type specifier - is assumed to be int. Note: C does not support default int
Lack of type specifier - is assumed to be int. Note: C does not support default int

Time:11-08

# define MAXQSIZE 100
Typedef struct {
QElemType * base;
Int the front;
Int rear;
} SqQueue;
# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0
Void exit (int value)

Typedef int the Status;
Typedef char QElemType;

The Status InitQueue (SqQueue & amp; Q)
{//constructs an empty queue Q
Q.b ase=new QElemType [MAXQSIZE];
if(! Q.b ase) exit (0);
Q.f ront=Q.r ear=0;
return OK;
}
The Status the EnQueue (SqQueue & amp; Q, QElemType e)
{//insert element for Q e new elements of the
If ((Q.r ear + 1) % MAXQSIZE==Q.f ront)
return ERROR;
Q.b ase [Q.r ear]=e;
Q.r ear=(Q.r ear + 1) % MAXQSIZE;
return OK;
}
The Status to DeQueue (SqQueue & amp; Q, QElemType & amp; E)
{//delete the Q team head, with e returns its value
If (Q.f ront==Q.r ear) return the ERROR;
E=Q.b ase [Q.f ront];
Q.f ront=(Q.f ront + 1) % MAXQSIZE;
return OK;
}
Int QueueLength (SqQueue Q)
{//returns the number of elements in the Q, i.e., the length of queue
Return (Q.r ear - Q.f ront + MAXQSIZE) % MAXQSIZE;
}
The Status GetHead (SqQueue Q)
{//return Q team head, don't change the head pointer
If (Q.f ront!=Q.r ear)
Return Q.b ase [Q.f ront];
}

CodePudding user response:

# define MAXQSIZE 100
Typedef char QElemType;
Typedef struct {
QElemType * base;
Int the front;
Int rear;
} SqQueue;
# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0
Void exit (int value);
Typedef int the Status;
  • Related