队列入队/出队列-创新互联
#include
using namespace std;
新闻标题:队列入队/出队列-创新互联
分享网址:http://cdiso.cn/article/dhecjc.html
using namespace std;
//定义一个结点类型
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;
}
新闻标题:队列入队/出队列-创新互联
分享网址:http://cdiso.cn/article/dhecjc.html