/*
This implementation of front always points to the current head node, rear always points to the End Node
Next Node
*/
# Include <stdio. h>
# Include <stdlib. h>
#define MAXNUM 10
#define datatype int
typedef struct queue{
int queue[MAXNUM];
int front;
int rear;
}queue;
void initqueue(queue** p)
{
*p = (queue* )malloc(sizeof(queue));
if(*p != NULL){
(*p)->front = 0;
(*p)->rear = 0;
}
}
int emptyqueue(queue** p)
{
int val;
val = ((*p)->front == (*p)->rear);
return val;
}
Void enqueue (queue ** P, datatype X) // insert X to the end of the team
{
If (* P)-> rear + 1) % maxnum = (* P)-> front ){
Printf ("the queue is full/N ");
Return;
}
(*p)->queue[(*p)->rear] = x;
(*p)->rear = ((*p)->rear+1)%MAXNUM;
}
Void delqueue (queue ** P, datatype * X) // deletes the queue Header element and returns it using X
{
If (* P)-> front = (* P)-> rear ){
Printf ("the queue is empty/N ");
Return;
}
*x = (*p)->queue[(*p)->front];
(*p)->front = ((*p)->front+1)%MAXNUM;
}
Void firstqueue (queue ** P, datatype * X) // return the queue Header element
{
* X = (* P)-> queue [(* P)-> front];
}
Void prqueue (queue ** p) // print the queue Element
{
Int I;
i = (*p)->front;
while(i != (*p)->rear){
printf("%c", (*p)->queue[i]);
i = (i + 1) % MAXNUM;
}
printf("/n");
}
int main(int argc, char** argv)
{
queue* p;
int c, i;
initqueue(&p);
printf("input queue node value:/n");
/***
while((c = getchar()) !='/n'){
enqueue(&p, c);
}
***/
prqueue(&p);
For (I = 0; I <3; I ++ ){
Delqueue (& P, & C); // deletes a Header element.
}
printf("/n");
enqueue(&p, '*');
enqueue(&p, '$');
prqueue(&p);
firstqueue(&p, &c);
printf("first queue is %c/n", c);
exit(0);
}