Definition at line 17 of file main.cpp.
◆ reverseKGroup()
Definition at line 20 of file main.cpp.
21 {
22 if (!head || k == 1) return head;
23
24
25 list<ListNode*> new_list;
26
27
28 stack<ListNode*> s;
29
31 bool stop = false;
32 while (1)
33 {
34
36 for (int i = 0; i < k; ++i)
37 {
38 if (fast == nullptr)
39 {
40 stop = true;
41 break;
42 }
44 }
45 if (stop)
46 break;
47
48
49 for (int i = 0; i < k; ++i)
50 {
51 s.push(ptr);
53 }
54
55
56 while (!s.empty())
57 {
58 new_list.push_back(s.top());
59 s.pop();
60 }
61 }
62
63
64 while (ptr != nullptr)
65 {
66 new_list.push_back(ptr);
68 }
69
70
71 head = new_list.front();
72 new_list.pop_front();
73 ptr = head;
75 {
78 }
80 return head;
81 }
Definition for singly-linked list.
References ListNode::next.
Referenced by main().
The documentation for this class was generated from the following file: