-
Notifications
You must be signed in to change notification settings - Fork 980
/
main.cpp
44 lines (37 loc) · 918 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "solution.h"
#include <iostream>
using namespace std;
ListNode *create_linkedlist(std::initializer_list<int> lst)
{
auto iter = lst.begin();
ListNode *head = lst.size() ? new ListNode(*iter++) : nullptr;
for (ListNode *cur=head; iter != lst.end(); cur=cur->next)
cur->next = new ListNode(*iter++);
return head;
}
void clear(ListNode *head)
{
while (head) {
ListNode *del = head;
head = head->next;
delete del;
}
}
void printList(ListNode *head) {
for (ListNode *cur = head; cur; cur = cur->next)
cout << cur->val << "->";
cout << "\b\b " << endl;
}
int main()
{
Solution s;
vector<ListNode *> vec{
create_linkedlist({1,3,5,7,9}),
create_linkedlist({2,4,6,8,10}),
create_linkedlist({0,11,12,13,14})
};
ListNode *ret = s.mergeKLists(vec);
printList(ret);
clear(ret);
return 0;
}