把输入函数修好了
This commit is contained in:
@@ -12,7 +12,7 @@ typedef struct bookNode {
|
|||||||
|
|
||||||
bool isEmpty(bookList);
|
bool isEmpty(bookList);
|
||||||
|
|
||||||
void insert(bookList &l);
|
void create(bookList &l);
|
||||||
|
|
||||||
void display(bookList *l);
|
void display(bookList *l);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,30 @@ bool isEmpty(bookList *l) {
|
|||||||
return false;
|
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) {
|
void display(bookList *l) {
|
||||||
if (isEmpty(l)) {
|
if (isEmpty(l)) {
|
||||||
|
|||||||
+1
-12
@@ -2,22 +2,11 @@
|
|||||||
#include "LinkList.h"
|
#include "LinkList.h"
|
||||||
using namespace std;
|
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() {
|
int main() {
|
||||||
bookList books = new bookNode;
|
bookList books = new bookNode;
|
||||||
books->next = NULL;
|
books->next = NULL;
|
||||||
insert(books);
|
create(books);
|
||||||
display(&books);
|
display(&books);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user