身首异处

This commit is contained in:
2024-10-19 00:04:17 +08:00
parent 10b6e6aa67
commit 39819cdf5e
4 changed files with 32 additions and 16 deletions
+3 -2
View File
@@ -3,5 +3,6 @@ project(homework2)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
add_executable(Test_LinkList LinkLits.cpp add_executable(test1 LinkLits.cpp
Test_LinkList.cpp) test1.cpp
LinkList.h)
+19
View File
@@ -0,0 +1,19 @@
#ifndef LINKLIST_H
#define LINKLIST_H
#include<string>
using namespace std;
typedef struct bookNode {
string id;
string name;
double price;
bookNode *next;
} book_node, *bookList;
bool isEmpty(bookList);
void insert(bookList &l);
void display(bookList *l);
#endif //LINKLIST_H
+4 -8
View File
@@ -1,23 +1,19 @@
#include <iostream> #include <iostream>
#include<iomanip> #include<iomanip>
#include"LinkList.h"
using namespace std; using namespace std;
typedef struct bookNode {
string id;
string name;
double price;
bookNode *next;
} book_node, *bookList;
bool is_list_empty(bookList *l) { bool isEmpty(bookList *l) {
if ((*l)->next == NULL) { if ((*l)->next == NULL) {
return true; return true;
} }
return false; return false;
} }
void display(bookList *l) { void display(bookList *l) {
if (is_list_empty(l)) { if (isEmpty(l)) {
printf("List is empty\n"); printf("List is empty\n");
} else { } else {
bookNode *temp = (*l)->next; bookNode *temp = (*l)->next;
@@ -1,13 +1,13 @@
#include <iostream> #include <iostream>
#include "LinkLits.cpp" #include "LinkList.h"
using namespace std; using namespace std;
void insert(bookList *l) { void insert(bookList &l) {
bookNode *temp = (*l)->next; bookNode *temp = l;
while (temp != NULL) { while (temp != NULL) {
cin >> (*temp).id >> (*temp).name >> (*temp).price; cin >> (*temp).id >> (*temp).name >> (*temp).price;
if (!(((*temp).id == "" && (*temp).name == "" && (*temp).price == 0))) { if (!(((*temp).id == "0" && (*temp).name == "0" && (*temp).price == 0))) {
temp = (*temp).next; temp = (*temp).next = new bookNode;
} else { } else {
temp = NULL; temp = NULL;
} }
@@ -17,7 +17,7 @@ void insert(bookList *l) {
int main() { int main() {
bookList books = new bookNode; bookList books = new bookNode;
books->next = NULL; books->next = NULL;
insert(&books); insert(books);
display(&books); display(&books);
return 0; return 0;
} }