typedef struct tag_Queue_Node_S
{
int QueueData;
struct tag_Queue_Node_S *next;
}Queue_Node_S;
typedef struct tag_Queue_Link_S
{
Queue_Node_S *front;
Queue_Node_S *rail;
}Queue_link_S;
int LinkQueue_Init(Queue_link_S **sl)
{
*sl = (Queue_link_S *)malloc(sizeof(Queue_link_S));
if(NULL == *sl)
{
return T_ERR;
}
(*sl)->front = NULL;
(*sl)->rail = NULL;
return T_OK;
}
/*入队*/
int LinkQueue_In(Queue_link_S **sl, int Element)
{
Queue_Node_S *p = NULL;
if(NULL == *sl)
{
return T_ERR;
}
p = (Queue_Node_S *)malloc(sizeof(Queue_Node_S));
if(NULL == p)
{
return T_ERR;
}
p->next = NULL;
p->QueueData = Element;
if((*sl)->front == NULL && (*sl)->rail == NULL)
{
(*sl)->front = p;
(*sl)->rail = p;
}
else
{
(*sl)->rail->next = p;
(*sl)->rail = p;
}
return T_OK;
}
/*出队*/
int LinkQueue_Out(Queue_link_S **sl ,int *Element)
{
Queue_Node_S *p = NULL;
if(((*sl)->front == NULL && (*sl)->rail == NULL) || (NULL == Element))
{
return T_ERR;
}
p = (*sl)->front;
*Element = p->QueueData;
if((*sl)->front == (*sl)->rail)
{
(*sl)->front = NULL;
(*sl)->rail = NULL;
}
else
{
(*sl)->front = p->next;
}
free(p);
return T_OK;
}
/*队列是否为空*/
int LinkQueue_IsEmpty(Queue_link_S **sl)
{
if((*sl)->front == (*sl)->rail)
{
return T_ERR;
}
else
{
return T_OK;
}
}
队列的链式实现源码
最新推荐文章于 2024-07-21 09:48:27 发布