
typedef struct DataNode
{
ElemType data;
struct DataNode *next;
}DataNode;
typedef struct
{
DataNode *front;
dataNode *rear;
}LinkQuNode;
//初始化带头点的链队
void InitQueue(LinkQuNode &q)
{
q = (LinkQuNode *)malloc(sizeof(LinkQuNode));
q->rear = q->front;
q->front->next = NULL;
}
//销毁带头结点的链队 //头指针指向空
bool DestroyQueue(LinkQuNode &q)
{
DataNode *p,*pre;
pre = q->front;
p = pre->next;
while(pre!=NULL)
{
free(pre);
pre = p;
p = p->next;
}
free(q);
}
//到头结点的链队判空
bool QueueEmpty(LinkQuNode &q)
{
return(q->rear == q->front);
}
//带头结点的入队 *** 作 从队尾入
bool Enqueue(LinkQuNode &q,ElemType e)
{
*s = (DataNode *)malloc(sizeof(DataNode));
s->next = NULL;
s->data = e;
q->rear->next = s;
q->rear = s;
return true;
}
//带头结点的出队 *** 作 //从对头后出
bool Dequeue(LinkQuNode &q,ElemType e)
{
if(q->front->next ==NULL)//(p->front == p->rear)效果一样
return false;
DataNode *t;
t= p->front ->next;
e = t->data;
p->front->next = t->next;
free(t);
return true;
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)