This program took me a lot of time, and the result certificate is not as good as the example above, hey... Dashboard
[Cpp]
# Include <STDIO. H>
# Include <STDLIB. H>
Typedef int ElemType;
Typedef struct LQNode
{
ElemType data;
Struct LQNode * next;
} LqueueNode;
Typedef struct
{
LqueueNode * rear;
LqueueNode * front;
} LinkQueue;
// Initialization
Void InitLQueue (LinkQueue * Q)
{
Q-> rear = NULL;
Q-> front = NULL;
}
// Enter the team
Int EnLQueue (LinkQueue * Q, ElemType x)
{
// Insert the primary x value of the data into the end of the Q queue of the leeching node. If the leeching is successful, 1 is returned; otherwise, 0 is returned.
LqueueNode * p;
P = (LqueueNode *) malloc (sizeof (LqueueNode ));
P-> data = x;
P-> next = NULL;
If (Q-> rear = NULL)
Q-> rear = Q-> front = p;
Else
{
Q-> rear-> next = p;
Q-> rear = p;
}
Return 1;
}
// Team out
Int DelQueue (LinkQueue * Q, ElemType * x)
{
// Delete the queue Header element and return its value with x.
LqueueNode * q;
If (Q-> front = NULL ){
Printf ("Queue is empty! ");
Return 0;
}
* X = Q-> front-> data;
Q = Q-> front;
Q-> front = Q-> front-> next;
If (Q-> front = NULL)
Q-> rear = NULL;
Free (q );
Return 1;
}
Void print (LinkQueue Q)
{
// Display all elements in the queue
Printf ("The queue elements are: \ n ");
While (Q. front! = Q. rear)
{
Printf ("% d", Q. front-> data );
Q. front = Q. front-> next;
}
Printf ("% d", Q. rear-> data );
Printf ("\ n ");
/* If (Q-> front = Q-> rear)
Printf ("Empty queue, no element ");
Else {
Printf ("the elements of this cyclic queue are :");
For (int k = 0; k <QueueLength (Q); k ++)
{
Printf ("% d", Q-> front-> data );
Q-> front = Q-> front-> next;
}
}*/
}
Void main ()
{
LinkQueue SCSI;
Int j, x;
InitLQueue (& SCSI );
Printf ("Input a integer \ n ");
Scanf ("% d", & j );
While (j! = 0)
{
If (j % 2 = 1)
EnLQueue (& SCSI, j );
Else
DelQueue (& SCSI, & x );
Print (SCSI );
Printf ("Input a integer \ n ");
Scanf ("% d", & j );
}
}
# Include <STDIO. H>
# Include <STDLIB. H>
Typedef int ElemType;
Typedef struct LQNode
{
ElemType data;
Struct LQNode * next;
} LqueueNode;
Typedef struct
{
LqueueNode * rear;
LqueueNode * front;
} LinkQueue;
// Initialization
Void InitLQueue (LinkQueue * Q)
{
Q-> rear = NULL;
Q-> front = NULL;
}
// Enter the team
Int EnLQueue (LinkQueue * Q, ElemType x)
{
// Insert the primary x value of the data into the end of the Q queue of the leeching node. If the leeching is successful, 1 is returned; otherwise, 0 is returned.
LqueueNode * p;
P = (LqueueNode *) malloc (sizeof (LqueueNode ));
P-> data = x;
P-> next = NULL;
If (Q-> rear = NULL)
Q-> rear = Q-> front = p;
Else
{
Q-> rear-> next = p;
Q-> rear = p;
}
Return 1;
}
// Team out
Int DelQueue (LinkQueue * Q, ElemType * x)
{
// Delete the queue Header element and return its value with x.
LqueueNode * q;
If (Q-> front = NULL ){
Printf ("Queue is empty! ");
Return 0;
}
* X = Q-> front-> data;
Q = Q-> front;
Q-> front = Q-> front-> next;
If (Q-> front = NULL)
Q-> rear = NULL;
Free (q );
Return 1;
}
Void print (LinkQueue Q)
{
// Display all elements in the queue
Printf ("The queue elements are: \ n ");
While (Q. front! = Q. rear)
{
Printf ("% d", Q. front-> data );
Q. front = Q. front-> next;
}
Printf ("% d", Q. rear-> data );
Printf ("\ n ");
/* If (Q-> front = Q-> rear)
Printf ("Empty queue, no element ");
Else {
Printf ("the elements of this cyclic queue are :");
For (int k = 0; k <QueueLength (Q); k ++)
{
Printf ("% d", Q-> front-> data );
Q-> front = Q-> front-> next;
}
}*/
}
Void main ()
{
LinkQueue SCSI;
Int j, x;
InitLQueue (& SCSI );
Printf ("Input a integer \ n ");
Scanf ("% d", & j );
While (j! = 0)
{
If (j % 2 = 1)
EnLQueue (& SCSI, j );
Else
DelQueue (& SCSI, & x );
Print (SCSI );
Printf ("Input a integer \ n ");
Scanf ("% d", & j );
}
}