重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//定义一个结点类型
typedef struct node
{
int data;
node* next;
}queuenode;
//定义队列的first,rear
typedef struct linkqueue
{
queuenode* first,*rear;
}queue;
//队列入队
queue *insert(queue *HQ,int x)
{
queuenode *s=new queuenode[sizeof(queuenode)];
s->data=x;
s->next=NULL;
if(HQ->rear==NULL)
{
HQ->first=s;
HQ->rear=s;
}
else
{
HQ->rear->next=s;
HQ->rear=s;
}
return HQ;
}
queue *del(queue *HQ)
{
queuenode *p=new queuenode[sizeof(queuenode)];
int x;
if(HQ->first==NULL)
{
cout<<"queue is empty"<
}
x=HQ->first->data;
p=HQ->first;
if(HQ->first==HQ->rear)
{
HQ->first=NULL;
HQ->rear=NULL;
}
else
{
HQ->first = p->next;
delete p;
}
return HQ;
}