50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#include <iostream>
|
|
#include<iomanip>
|
|
#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;
|
|
}
|
|
}
|
|
}
|