第一题写完辣

This commit is contained in:
2024-10-19 00:53:12 +08:00
parent f675daad41
commit 0dd0c19bd1
3 changed files with 15 additions and 0 deletions
+1
View File
@@ -16,4 +16,5 @@ void create(bookList &l);
void display(bookList *l); void display(bookList *l);
int getLength(bookList *l);
#endif //LINKLIST_H #endif //LINKLIST_H
+13
View File
@@ -47,3 +47,16 @@ void display(bookList *l) {
} }
} }
} }
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;
}
+1
View File
@@ -7,6 +7,7 @@ int main() {
bookList books = new bookNode; bookList books = new bookNode;
books->next = NULL; books->next = NULL;
create(books); create(books);
cout << getLength(&books) << endl;
display(&books); display(&books);
return 0; return 0;
} }