Update the access() function of linked_list

This commit is contained in:
Yudong Jin
2023-01-10 00:46:04 +08:00
parent aaa2ff29f9
commit d6d6a16c7e
7 changed files with 13 additions and 12 deletions

View File

@ -28,9 +28,9 @@ void remove(ListNode* n0) {
/* 访问链表中索引为 index 的结点 */
ListNode* access(ListNode* head, int index) {
for (int i = 0; i < index; i++) {
head = head->next;
if (head == nullptr)
return nullptr;
head = head->next;
}
return head;
}