delete-the-middle-node-of-a-linked-list 1.0.0
Delete the Middle Node of a Linked List
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

ListNodedeleteMiddle (ListNode *head)
 

Detailed Description

Definition at line 17 of file main.cpp.

Member Function Documentation

◆ deleteMiddle()

ListNode * Solution::deleteMiddle ( ListNode head)
inline

Definition at line 20 of file main.cpp.

21 {
22 if (head == NULL || head->next == NULL) // 0-el, 1-el
23 return NULL;
24
25 ListNode* slow = head;
26 ListNode* fast = head;
27 ListNode* prev = NULL;
28
29 while (fast != NULL && fast->next != NULL)
30 {
31 fast = fast->next->next;
32 prev = slow;
33 slow = slow->next;
34 }
35
36 prev->next = slow->next;
37 delete slow;
38
39 return head;
40 }
Definition for singly-linked list.
Definition main.cpp:9
ListNode * next
Definition main.cpp:11

References ListNode::next.


The documentation for this class was generated from the following file: