{
Append_Sq1(La,e); La.length++; } i++; } }
DS04-PE38 /**********
【题目】假设以带头结点的循环链表表示队列,并且 只设一个指针指向队尾元素结点(注意不设头指针), 试编写相应的队列初始化、入队列和出队列的算法。 带头结点循环链队列CLQueue的类型定义为: typedef struct LQNode { ElemType data;
struct LQNode *next; } LQNode, *CLQueue; **********/
Status InitCLQueue(CLQueue &rear) // 初始化空队列 {
rear=(CLQueue)malloc(sizeof(LQNode)); if( NULL==rear ) return ERROR; rear->next=rear; return OK; }
Status EnCLQueue(CLQueue &rear, ElemType x) // 入队 {
LQNode *p;
p=(LQNode*)malloc(sizeof(LQNode)); if( NULL==p ) return ERROR; p->data=x; p->next=rear->next; rear->next=p; rear=p; return OK; }
Status DeCLQueue(CLQueue &rear, ElemType &x) // 出队 {
if( rear->next==rear ) return ERROR; CLQueue p;
p=rear->next->next; x=p->data; if( p==rear ) {
rear=rear->next; rear->next=p; } else {
rear->next->next=p->next; }
return OK; }
DS04-PE62 /**********
【题目】试写一算法,在带头结点单链表L插入第i元素e。 带头结点单链表的类型定义为: typedef struct LNode { ElemType data; struct LNode *next; } LNode, *LinkList; **********/
int LengthLinkList(LinkList L) {
LinkList p=L; int length=0; while( p->next ) {
length++; p=p->next; }
return length; }
Status Insert_L(LinkList L, int i, ElemType e)
/* 在带头结点单链表L插入第i元素e,并返回OK。*/ /* 若参数不合理,则返回ERROR。 */ {
if( NULL==L ) return ERROR; int length=LengthLinkList(L);
if( i&g