Debian Codegraph @

clone_sample_test.go

raw
1 // Copyright 2019 Huan Du. All rights reserved.
2 // Licensed under the MIT license that can be found in the LICENSE file.
3
4 package clone
5
6 import "fmt"
7
8 func ExampleSlowly() {
9 type ListNode struct {
10 Data int
11 Next *ListNode
12 }
13 node1 := &ListNode{
14 Data: 1,
15 }
16 node2 := &ListNode{
17 Data: 2,
18 }
19 node3 := &ListNode{
20 Data: 3,
21 }
22 node1.Next = node2
23 node2.Next = node3
24 node3.Next = node1
25
26 // We must use `Slowly` to clone a circular linked list.
27 node := Slowly(node1).(*ListNode)
28
29 for i := 0; i < 10; i++ {
30 fmt.Println(node.Data)
31 node = node.Next
32 }
33
34 // Output:
35 // 1
36 // 2
37 // 3
38 // 1
39 // 2
40 // 3
41 // 1
42 // 2
43 // 3
44 // 1
45 }