十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
//定义一个结点类型
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;
}