From 67f5fe11872ffb7ef266a21f55004a4738e18599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=8E=E7=A5=BE?= <13452906+bhxqtd@user.noreply.gitee.com> Date: Fri, 22 Dec 2023 06:57:37 +0000 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC2=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘祎祾 <13452906+bhxqtd@user.noreply.gitee.com> --- .../\347\254\2542\347\253\240/exp2-2.cpp" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "2224020137/\347\254\2542\347\253\240/exp2-2.cpp" diff --git "a/2224020137/\347\254\2542\347\253\240/exp2-2.cpp" "b/2224020137/\347\254\2542\347\253\240/exp2-2.cpp" new file mode 100644 index 00000000..597bf726 --- /dev/null +++ "b/2224020137/\347\254\2542\347\253\240/exp2-2.cpp" @@ -0,0 +1,33 @@ +#include "linklist.cpp" +int main() +{ + LinkNode *h; + ElemType e; + printf("单链表的基本运算如下:\n"); + printf(" (1)初始化单链表h\n"); + InitList(h); + printf(" (2)依次采用尾插法插入a,b,c,d,e元素\n"); + ListInsert(h,1,'a'); + ListInsert(h,2,'b'); + ListInsert(h,3,'c'); + ListInsert(h,4,'d'); + ListInsert(h,5,'e'); + printf(" (3)输出单链表h:"); + DispList(h); + printf(" (4)单链表h长度:%d\n",ListLength(h)); + printf(" (5)单链表h为%s\n",(ListEmpty(h)?"空":"非空")); + GetElem(h,3,e); + printf(" (6)单链表h的第3个元素:%c\n",e); + printf(" (7)元素a的位置:%d\n",LocateElem(h,'a')); + printf(" (8)在第4个元素位置上插入f元素\n"); + ListInsert(h,4,'f'); + printf(" (9)输出单链表h:"); + DispList(h); + printf(" (10)删除h的第3个元素\n"); + ListDelete(h,3,e); + printf(" (11)输出单链表h:"); + DispList(h); + printf(" (12)释放单链表h\n"); + DestroyList(h); + return 1; +} \ No newline at end of file -- Gitee