定义好第一题结构体、初始化函数、插入函数

This commit is contained in:
2024-10-10 12:56:25 +08:00
parent ddae8207e3
commit ae40fb0d46
3 changed files with 35 additions and 7 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ project(homework2)
set(CMAKE_CXX_STANDARD 20)
add_executable(homework2 main.cpp)
add_executable(test1 test1.cpp)
-6
View File
@@ -1,6 +0,0 @@
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
+34
View File
@@ -0,0 +1,34 @@
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct node {
string id;
string name;
double price;
struct node *next;
} node, book_list*;
void init_list(book_list *books) {
*books = new node();
(*books)->next = NULL;
}
void create_from_end(book_list *books) {
node *r = reinterpret_cast<node *>(books);
node *s = new node();
do {
cin >> s->id >> s->name >> s->price;
if (s->id == "0" && s->name == "0" && s->price == 0) {
r->next = s;
} else {
r->next = NULL;
}
} while (r->next != NULL);
}
int main() {
return 0;
}