Definition at line 17 of file main.cpp.
◆ removeNthFromEnd()
Definition at line 20 of file main.cpp.
21 {
22
25
26
27 for (int i = 0; i < n; ++i)
28 {
29 if (current == nullptr)
30 return head;
31 current = current->
next;
32 }
33
34
35 if (current == nullptr)
36 {
39 delete removed;
40 return head;
41 }
42
43
44 while (current->
next !=
nullptr)
45 {
46 current = current->
next;
47 remove_next = remove_next->
next;
48 }
49
50
53 removed->
next =
nullptr;
54 delete removed;
55
56 return head;
57 }
Definition for singly-linked list.
References ListNode::next.
Referenced by main().
The documentation for this class was generated from the following file: