From 10b6e6aa676447313aded4cba5b805fcdbae57cb Mon Sep 17 00:00:00 2001 From: msksbr Date: Fri, 18 Oct 2024 23:54:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E7=9D=80=E5=86=99=E4=BA=86=E4=B8=AA?= =?UTF-8?q?=E9=93=BE=E8=A1=A8.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework2/CMakeLists.txt | 7 +++++++ homework2/LinkLits.cpp | 29 +++++++++++++++++++++++++++++ homework2/Test_LinkList.cpp | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 homework2/CMakeLists.txt create mode 100644 homework2/LinkLits.cpp create mode 100644 homework2/Test_LinkList.cpp diff --git a/homework2/CMakeLists.txt b/homework2/CMakeLists.txt new file mode 100644 index 0000000..5d741ae --- /dev/null +++ b/homework2/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.29) +project(homework2) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(Test_LinkList LinkLits.cpp + Test_LinkList.cpp) diff --git a/homework2/LinkLits.cpp b/homework2/LinkLits.cpp new file mode 100644 index 0000000..2b55ce0 --- /dev/null +++ b/homework2/LinkLits.cpp @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +typedef struct bookNode { + string id; + string name; + double price; + bookNode *next; +} book_node, *bookList; + +bool is_list_empty(bookList *l) { + if ((*l)->next == NULL) { + return true; + } + return false; +} + +void display(bookList *l) { + if (is_list_empty(l)) { + printf("List is empty\n"); + } else { + bookNode *temp = (*l)->next; + while (temp != NULL) { + cout << temp->id << " " << temp->name << " " << fixed << setprecision(2) << temp->price << endl; + temp = temp->next; + } + } +} diff --git a/homework2/Test_LinkList.cpp b/homework2/Test_LinkList.cpp new file mode 100644 index 0000000..95e567b --- /dev/null +++ b/homework2/Test_LinkList.cpp @@ -0,0 +1,23 @@ +#include +#include "LinkLits.cpp" +using namespace std; + +void insert(bookList *l) { + bookNode *temp = (*l)->next; + while (temp != NULL) { + cin >> (*temp).id >> (*temp).name >> (*temp).price; + if (!(((*temp).id == "" && (*temp).name == "" && (*temp).price == 0))) { + temp = (*temp).next; + } else { + temp = NULL; + } + } +} + +int main() { + bookList books = new bookNode; + books->next = NULL; + insert(&books); + display(&books); + return 0; +}