第一题写完辣
This commit is contained in:
@@ -16,4 +16,5 @@ void create(bookList &l);
|
||||
|
||||
void display(bookList *l);
|
||||
|
||||
int getLength(bookList *l);
|
||||
#endif //LINKLIST_H
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ int main() {
|
||||
bookList books = new bookNode;
|
||||
books->next = NULL;
|
||||
create(books);
|
||||
cout << getLength(&books) << endl;
|
||||
display(&books);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user