输入修好了

This commit is contained in:
2024-10-10 13:30:25 +08:00
parent ae40fb0d46
commit b98d65fa23
+17 -5
View File
@@ -8,7 +8,7 @@ typedef struct node {
string name; string name;
double price; double price;
struct node *next; struct node *next;
} node, book_list*; } node, *book_list;
void init_list(book_list *books) { void init_list(book_list *books) {
*books = new node(); *books = new node();
@@ -16,19 +16,31 @@ void init_list(book_list *books) {
} }
void create_from_end(book_list *books) { void create_from_end(book_list *books) {
node *r = reinterpret_cast<node *>(books); node *r = *books;
node *s = new node(); node *s = new node();
do { do {
cin >> s->id >> s->name >> s->price; cin >> s->id >> s->name >> s->price;
if (s->id == "0" && s->name == "0" && s->price == 0) { if (s->id == "0" && s->name == "0" && s->price == 0) {
r->next = s;
} else {
r->next = NULL; r->next = NULL;
} else {
r->next = s;
}
r = r->next;
} while (r != NULL);
}
void display(book_list *books) {
while ((*books)->next != NULL) {
*books = (*books)->next;
cout << (*books)->id << " " << (*books)->name << " " << fixed << setprecision(2) << (*books)->price << endl;
} }
} while (r->next != NULL);
} }
int main() { int main() {
book_list *books;
init_list(books);
create_from_end(books);
display(books);
return 0; return 0;
} }