用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.
来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/05 16:01:46
用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.
主函数什么的都不用写,只写这两个算法!急!急!急!
主函数什么的都不用写,只写这两个算法!急!急!急!
先写个循环链表的实现
然后 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);
}
}
然后 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);
}
}
用循环单链表实现循环队列,写出插入,和删除的算法,只要这两个函数的算法就行了,有头尾指针.
设用一个循环链表来表示一个队列,该队列只设一个尾指针,试分别编写向循环队列插入和删除一个结点的算法
对于循环队列,试写出求队列长度的算法.
循环队列采用设置标志的方法来区分队列的满和空 实现这个算法!
有一个循环单链表的长度大于1,表中既无头结点也无头指针.S为指向链表中某结点的指针,写算法,删除结点S
2.假设以数组A[m]存放循环队列的元素,其头尾指针分别为front 和rear,则当前队列中的元素个数为()A:(re
假设以数组A[m]存放循环队列的元素,其头尾指针分别为front和rear,则当前队列中的判空条件为什么
求循环队列的元素个数算法,已知front 和 rear,还有容量数,怎么求队列中的循环元素个数?
循环队列用数组A[0,m-1]存放其元素值,已知其头尾指针分别是front和rear,则当前队列中的元素个数是
递归算法举例不许用if,不许用for循环算出10到20相加的和,递归算法怎么实现
设循环列队中数组的下标是1~n.其头尾指针分别为f,r,则队列中元素个数为?
数学循环结构的概念算法中的循环结构是由__来实现的,循环语句由__语句和语句组成.