作业帮 > 综合 > 作业

用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/04/28 23:15:05
用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.
主函数什么的都不用写,只写这两个算法!急!急!急!
用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.
先写个循环链表的实现
然后 C++ 用继承
C就组合吧,下面写个C的实现
typedef struct CircleListNode{
Datatype d;
struct CircleList *pre,*nxt;
}*CircleList,CirListNode;
typedef struct
{
CircleList Head;
int num;
}CircleQueue;
void insertFront(CircleList *L,d);
{
if(!L)return NULL;
if(*L==NULL)
{
*L=(CircleList) malloc(sizeof(CirListNode));
*L->nxt= *L->pre=*L ;
*L->d=d;
}
else
{
CircleList p =(CircleList) malloc(sizeof(CirListNode));
p->nxt=*L;
p->pre=*L->pre;
*L->pre->nxt=p;
*L->pre=p;
*L=p;
}
}
void DeleteBack(CircleList *L)
{ CircleList r=*L->pre;
if(*L->nxt =*L){ free(*L);*L=NULL;return ;}
r->pre->nxt =*L;
*L->pre=r->pre;
free(r);
}
void InsertQueue(CircleQueue *que,Datatype d)
{
if(!que)return;
insertFront(&que->Head,d);
que->num ++;
}
void DeletQueue(CircleQueue *que)
{
if(que->num>0)
{
DeleteBack(&que->Head);
que->num--;
}
}
void InitQueue(CircleQueue *que)
{
if(!que)return;
que->Head=NULL;
que->num=0;
}
Datatype * GetBackData(const CircleQueue *que)
{
if(!que)return NULL;
if(!que->Head)return NULL;
if(que->numHead->pre->d);
}
void ClearQueue(CircleQueue *que)
{
if(!que)return ;
while(que->num>0)
{
DeletQueue(que);
}
}