From 925b1608e92b185f42351ef9a2b6374edc38b056 Mon Sep 17 00:00:00 2001 From: wuhangkai <2048572486@qq.com> Date: Thu, 15 Jun 2023 19:05:08 +0800 Subject: [PATCH] 2 --- 代码 | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/代码 b/代码 index 82fdc44..0ba075b 100644 --- a/代码 +++ b/代码 @@ -360,3 +360,167 @@ return i; } +Status InitList(LinkList& L)//链表初始化 + +{ + +L = (LinkList)malloc(sizeof(LNode)); + +if (!L) + +{ + +exit(OVERFLOW); + +} + +L->next = NULL; + +return OK; + +} + +Status ListInsert_L(LinkList& L, int i, ElemType e)//在第i个位置之前插入元素e + +{ + +LinkList p = L; + +int j = 0; + +while (p && j < i - 1)//注意是i-1,因为要找被插入元素的前一个元素 + +{ + +p = p->next; + +j++; + +} + +if (!p || j > i - 1) + +{ + +return ERROR; + +} + +LinkList s = (LinkList)malloc(sizeof(LNode)); + +if (!s) + +{ + +exit(OVERFLOW); + +} + +s->data = e; + +s->next = p->next; + +p->next = s; + +return OK; + +} + +Status ListEmpty(LinkList L)//判断链表是否为空 + +//空表:头指针和头结点仍然存在,但头结点指向NULL + +{ + +if (L->next) + +{ + +return FALSE; + +} + +else + +{ + +return TRUE; + +} + +} + +Status DelFirst(LinkList L, LNode*& q)//删除链表中第一个结点并以q返回 + +{ + +if (!L->next) + +{ + +return ERROR; + +} + +q = L->next; + +L->next = q->next; + +return OK; + +} + +LNode* GetHead(LinkList L)//返回链表头结点 + +{ + +return L; + +} + +ElemType GetCurElem(LNode* p)//已知p指向线性链表中的一个结点,返回p所指结点中元素的值 + +{ + +return p->data; + +} + +void PrintEventList()//打印事件链表  + +{  + +printf("Current Eventlist is:\n"); + +ListTraverse(ev); + +} + +Status ListTraverse(LinkList& L) //遍历链表   + +{ + +LNode* p = L->next; + +if (!p) { + +printf("List is empty.\n"); + +return ERROR; + +} + +while (p != NULL) { + +printf("OccurTime:%d,Event Type:%d\n", p->data.OccurTime, p->data.NType); + +p = p->next; + +} + +printf("\n"); + +return OK; + +} +