aboutsummaryrefslogtreecommitdiff
path: root/content/go-maps-in-action/list.go
blob: 02bea2c510aeb620797c6e5ad3c5e221ca35d799 (plain)
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
// Copyright 2013 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build OMIT

package main

import "fmt"

func main() {
	// START OMIT
	type Node struct {
		Next  *Node
		Value interface{}
	}
	var first *Node

	visited := make(map[*Node]bool) // HL
	for n := first; n != nil; n = n.Next {
		if visited[n] { // HL
			fmt.Println("cycle detected")
			break
		}
		visited[n] = true // HL
		fmt.Println(n.Value)
	}
	// END OMIT
}