The basic operation implementation code of chain queue initialization, Enqueue, and outbound is as follows:
#include <iostream>
using namespace Std;
#define TRUE 1
#define FALSE 0
Chain Queue definition
typedef struct NODE
{
int data;//data field
struct Node *next;//pointer field
}linkqueuenode;
typedef struct
{
Linkqueuenode *front;//Team head pointer front
Linkqueuenode *rear;//team head pointer rear
}linkqueue;
Initialize Q to an empty chain queue
int Initqueue (Linkqueue *q)
{
Q->front = (Linkqueuenode *) malloc (sizeof (Linkqueuenode));
if (q->front! = NULL)
{
Q->rear = q->front;
Q->front->next = NULL;
return TRUE;
}
Else
{
return false;//Overflow
}
}
Inserting a data element x into the queue Q
int Enterqueue (linkqueue *q,int x)
{
Linkqueuenode *newnode;
NewNode = (Linkqueuenode *) malloc (sizeof (Linkqueuenode));
if (NewNode! = NULL)
{
newnode->data=x;
Newnode->next = NULL;
Q->rear->next = NewNode;
Q->rear = NewNode;
return TRUE;
}
Else
{
return false;//Overflow
}
}
Queue Q's team head element out of the team and store it in the storage space referred to by x
int Deletequeue (linkqueue *q, int *x)
{
Linkqueuenode *p;
if (Q->front = = q->rear)
{
return FALSE;
}
p = q->front->next;
Q->front->next = p->next;//Team head element p out team
if (q->rear==p)//If there is only one element p in the team, then p becomes the empty team after the team
{
Q->rear= q->front;
}
*x = p->data;
Free (P);//freeing up storage space
return TRUE;
}
This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1771880
Implementation of chain queue initialization, queuing, and team-out operation