//LinkList.cpp #include #include #include"LinkList.h" using namespace std; bool isEmpty(bookList *l) { if ((*l)->next == NULL) { return true; } 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)) { printf("List is empty\n"); } else { bookNode *temp = (*l)->next; while (temp != NULL) { cout << temp->id << " " << temp->name << " " << fixed << setprecision(2) << temp->price << endl; temp = temp->next; } } } int getLength(bookList *l) { if (isEmpty(l)) { return 0; } bookNode *temp = (*l)->next; int length = 0; while (temp != NULL) { length++; temp = temp->next; } return length; }