把输入函数修好了

This commit is contained in:
2024-10-19 00:48:14 +08:00
parent 39819cdf5e
commit f675daad41
3 changed files with 26 additions and 13 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ typedef struct bookNode {
bool isEmpty(bookList);
void insert(bookList &l);
void create(bookList &l);
void display(bookList *l);
+24
View File
@@ -11,6 +11,30 @@ bool isEmpty(bookList *l) {
return false;
}
void create(bookList &l) {
bookNode *input = new bookNode;
input->next = NULL;
bookNode *temp = l; // 从头节点开始
bool flag = true;
while (flag) {
cin >> input->id >> input->name >> input->price;
if (input->id == "0" && input->name == "0" && input->price == 0) {
flag = false;
delete input;
} else {
if (temp == l) {
l->next = input;
} else {
temp->next = input;
}
temp = input;
input = new bookNode;
input->next = NULL;
}
}
}
void display(bookList *l) {
if (isEmpty(l)) {
+1 -12
View File
@@ -2,22 +2,11 @@
#include "LinkList.h"
using namespace std;
void insert(bookList &l) {
bookNode *temp = l;
while (temp != NULL) {
cin >> (*temp).id >> (*temp).name >> (*temp).price;
if (!(((*temp).id == "0" && (*temp).name == "0" && (*temp).price == 0))) {
temp = (*temp).next = new bookNode;
} else {
temp = NULL;
}
}
}
int main() {
bookList books = new bookNode;
books->next = NULL;
insert(books);
create(books);
display(&books);
return 0;
}