forked from pezy/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (38 loc) · 857 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
44
45
46
#include "solution.h"
#include <iostream>
using namespace std;
void print_randomlist(RandomListNode *head)
{
while (head) {
cout << head->label << " ";
if (head->random) cout << head->random->label << " ";
else cout << "NULL" << " ";
head = head->next;
}
cout << endl;
}
void clear(RandomListNode *head)
{
while (head) {
RandomListNode *tmp = head;
head = head->next;
delete tmp;
}
}
int main()
{
Solution s;
RandomListNode head(0);
RandomListNode node(1);
RandomListNode last(2);
head.next = &node;
node.next = &last;
head.random = &last;
node.random = &head;
last.random = &last;
print_randomlist(&head);
RandomListNode *new_head = s.copyRandomList(&head);
print_randomlist(new_head);
clear(new_head);
return 0;
}