From 77573a7be697304663501548ee5c909a87a0851c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E6=A5=A0?= <87896121@qq.com> Date: Tue, 25 Apr 2023 16:00:41 +0800 Subject: [PATCH] c2c3c4c5 --- README.md | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 06a566e..6e57161 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,29 @@ void ShowMainMenu() 函数原形:void ShowLibInfo(const Book* book, const Reader* reader); 功能:接受两个形参,分别是图书的链表地址,读者的链表地址,并遍历两个链表,显示出图书的数量和读者的数量 ``` - +void ShowLibInfo(const Book* book1, const Reader* reader1) +{ + Book* book = book1; + Reader* reader = reader1; + + + int bookNUm = 0, readerNUm = 0, mangerNUm = 0; + while (book != NULL) + { + bookNUm++; + book = book->next; + } + while (reader != NULL) + { + readerNUm++; + reader = reader->next; + } + + printf("本图书馆共有藏书%d本,读者%d人\n", bookNUm, readerNUm); + printf("按任意键返回\n"); + getchar(); + return; +} ``` @@ -87,7 +109,18 @@ void ShowMainMenu() 1) 函数原形: void ShowLibBook(Book* book); 2) 功能: 接受一个形参:图书的链表地址,遍历该链表,显示出所有图书的信息 ``` - +void ShowLibBook(Book* book1) +{ + Book* book = book1; + while (book != NULL) + { // \t :制表符 + printf("%d\t%s\t%s\t%s\t%d\n", book->iNum, book->acName, book->acAuthor, book->acPress, book->iAmount); + book = book->next; + } + printf("\n按任意键返回\n"); + getchar(); + return; +} ``` @@ -97,7 +130,78 @@ void ShowMainMenu() 1) 函数原形: Book* AddBook(Book* book); 2) 功能: 接受一个形参:图书的链表地址,利用尾插对链表进行修改,添加图书 ``` - +Book* AddBook(Book* book1) +{ + Book* book = book1; + + if (book == NULL) + { + + Book* tmp = (Book*)malloc(sizeof(Book)); + tmp->next = NULL; + assert(tmp); + printf("输入书的编号:"); + scanf("%d", &tmp->iNum); + getchar(); + printf("输入书的名称:"); + gets(&tmp->acName); + printf("输入书的作者:"); + gets(tmp->acAuthor); + printf("输入书的出版社:"); + gets(tmp->acPress); + printf("输入书的库存量:"); + scanf("%d", &tmp->iAmount); + book = tmp; + + printf("按任意键返回\n"); + getchar(); + return book; + + return; + } + + while (1) + { + while (book->next == NULL) + { + int flag = 1; + while (flag) + { + Book* tmp = (Book*)malloc(sizeof(Book)); + + tmp->next = NULL; + assert(tmp); + printf("输入书的编号:"); + scanf("%d", &tmp->iNum); + getchar(); + printf("输入书的名称:"); + gets(&tmp->acName); + printf("输入书的作者:"); + gets(tmp->acAuthor); + printf("输入书的出版社:"); + gets(tmp->acPress); + printf("输入书的库存量:"); + scanf("%d", &tmp->iAmount); + + book->next = tmp; + + printf("是否继续输入:1==>继续\t0==>结束\t"); + scanf("%d", &flag); + getchar(); + if (flag == 0) + { + printf("按任意键返回\n"); + getchar(); + return book1; + } + } + } + book = book->next; + } + printf("按任意键返回\n"); + getchar(); + return; +} ``` @@ -107,7 +211,40 @@ void ShowMainMenu() 1)函数原形: Book* DealoldBook(Book* book); 2) 功能: 接受一个形参:图书链表的地址,遍历该链表,用书的编号进行匹配,找到该图书后删除该图书,否则返回 ``` - +Book* DealoldBook(Book* book1) +{ + Book* book = book1; + Book* prev = book1; + printf("输入要处理旧书的编号:"); + int id; + scanf("%d", &id); + getchar(); + while (book != NULL) + { + + if (id == book->iNum) + { + if (book1 == book) + { + book = book->next; + free(prev); + return book; + } + prev->next = book->next; + free(book); // free():释放资源 + printf("已将旧书处理掉!\n"); + printf("按任意键返回\n"); + getchar(); + return book1; + } + prev = book; + book = book->next; + } + printf("没有找到该图书\n"); + printf("按任意键返回\n"); + getchar(); + return book1; +} ```