本题与上题本质上相同现用类C语言编写入队和出队算法
()void EnQueue (LinkedList rear ElemType x)
// rear是带头结点的循环链队列的尾指针本算法将元素x插入到队尾
{ s= (LinkedList) malloc (sizeof(LNode)); //申请结点空间
s>data=x; s>next=rear>next; //将s结点链入队尾
rear>next=s; rear=s; //rear指向新队尾
}
()void DeQueue (LinkedList rear)
// rear是带头结点的循环链队列的尾指针本算法执行出队操作操作成功输出队头元素否则给出出错信息
{ if (rear>next==rear) { printf(队空\n); exit();}
s=rear>next>next; //s指向队头元素
rear>next>next=s>next; //队头元素出队
printf (出队元素是s>data);
if (s==rear) rear=rear>next; //空队列
free(s);
}
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []