64,648
社区成员
发帖
与我相关
我的任务
分享
typedef class BookTree {
private:
BorrowedBook book;
BookTree* lchild;
BookTree* rchild;
public:
void in();
friend void insert(BookTree*&, string&, bool&);
};
void insert(BookTree*& t,string& id,bool& flag) {
if (flag) return;
if (t != NULL) {
if (t->book.id == id) {
cout << "-----此书已存在,库存+1-----" << endl;
t->book.rest++;
t->book.stock++;
flag = true;
}
else if (t->book.id > id)
insert(t->lchild, id, flag);
else insert(t->rchild, id, flag);
}
else {
t = new BookTree;
cout << "请输入书名:";
cin >> t->book.name; cout << endl;
cout << "请输入作者:";
cin >> t->book.auth; cout << endl;
t->book.rest = 1;
t->book.stock = 1;
cout << "-----存入成功-----" << endl;
flag = true;
}
}
void BookTree::in() {
cout << "请输入书号:";
string id;
cin >> id;
cout << endl;
bool flag = false;
insert(this, id, flag);
}