顺序队列问题 C语言的~

来源:百度知道 编辑:UC知道 时间:2024/05/14 19:52:09
假设循环队列中只设rear和length来分别表示队尾元素的位置和队中元素的个数,写出相应的入队和出队程序。

急喔~C语言的~

void enqueue(LNODE **hpt,LNODE **tpt,QNODE e)
{

LNODE *p=(LNODE *)malloc(sizeof(LNODE)) ;
p->data=e;
p->next=NULL;
if(*hpt==NULL) *tpt=*hpt=p;
else *tpt=(*tpt)->next=p;

}

int dequeue (LNODE **hpt,LNODE **tpt,QNODE *cp)
{
LNODE *p=*hpt;
if(*hpt==NULL) return 1;
*cp=(*hpt)->data;
*hpt=(*hpt)->next;
if(*hpt==NULL) *tpt=NULL;
free(p);
return 0;

}