关于入队(链队)的问题!新手求教
设有头指针和尾指针,原来是个空队,然后开始入队!typedef struct queue1
{
int data;
struct queue1 *next;
}queue;
typedef struct
{
queue *front;
queue *end;
}lqueue;
void init_lqueue(lqueue lq) //设置一个空队
{
lq.front=(queue *)malloc(sizeof(queue));
lq.end=(queue *)malloc(sizeof(queue));
lq.front->next=NULL;
lq.end=lq.front;
}
queue *enqueue(lqueue lq,int y) //入队操作
{
queue *s;
queue *head;
if(lq.front!=lq.end)
{
s=(queue *)malloc(sizeof(queue));
s->data=y;
s->next=NULL;
lq.end->next=s;
lq.end=s;
head=lq.front;
}
else
{
s=(queue *)malloc(sizeof(queue));
s->data=y;
s->next=NULL;
lq.front=s;
lq.end=s;
head=s;
}
return head;
}
帮看下入队操作,怎么处理头指针和尾指针?