From ead96ae9eea5234d9862528342554950ae37c173 Mon Sep 17 00:00:00 2001 From: msksbr Date: Sat, 19 Oct 2024 18:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E9=A2=98=E7=9A=84=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=86=99=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework2/CMakeLists.txt | 4 ++++ homework2/test3.cpp | 2 +- homework2/test4.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 homework2/test4.cpp diff --git a/homework2/CMakeLists.txt b/homework2/CMakeLists.txt index a8d698f..1fc8119 100644 --- a/homework2/CMakeLists.txt +++ b/homework2/CMakeLists.txt @@ -14,3 +14,7 @@ add_executable(test3 test3.cpp LinkList.h LinkList.cpp ) +add_executable(test4 test4.cpp + LinkList.h + LinkList.cpp +) diff --git a/homework2/test3.cpp b/homework2/test3.cpp index 11489e2..357f3f3 100644 --- a/homework2/test3.cpp +++ b/homework2/test3.cpp @@ -1,6 +1,6 @@ //test3.cpp #include -#include"LinkList.h" +#include"LinkList.h" //LinkList类见实验一 using namespace std; void alter_to_110_percent(bookList &l) { diff --git a/homework2/test4.cpp b/homework2/test4.cpp new file mode 100644 index 0000000..1ec628d --- /dev/null +++ b/homework2/test4.cpp @@ -0,0 +1,31 @@ +//test4.cpp +#include +#include"LinkList.h" //LinkList类见实验一 +using namespace std; + +void create_with_count(bookList &l, int count) { + bookNode *input = new bookNode; + input->next = NULL; + bookNode *temp = l; + for (int i = 0; i < count; i++) { + cin >> input->id >> input->name >> input->price; + if (temp == l) { + l->next = input; + } else { + temp->next = input; + } + temp = input; + input = new bookNode; + input->next = NULL; + } +} + +int main() { + bookList books = new bookNode; + books->next = NULL; + int count; + cin >> count; + create_with_count(books, count); + display(&books); + return 0; +}