我对编程很陌生,一直在尝试按字母顺序插入标题,但我的插入功能似乎没有工作。请帮忙!
class Book {
public:
Book() {
}
;
Book(char *newTitle) {
strcpy(title, newTitle);
}
char *getBook() {
return title;
}
int compareTo(Book *getbook) {
return (strcmp(title, getbook->title));
}
private:
char title[81];
};
void BookList::insert(Book *newBook) {
BookNode *node = new BookNode(newBook);
BookNode *current = NULL;
BookNode *previous = current;
node->next = NULL;
current = head;
if (current == NULL) {
head = node;
head->next = NULL;
}
else {
while (current->next != NULL && (newBook->compareTo(current->book) > 0)) {
previous = current;
current = current->next;
}
node->next = previous->next;
previous->next = node;
}
}