-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_list.htm
143 lines (143 loc) · 12 KB
/
container_list.htm
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head profile="http://a9.com/-/spec/opensearch/1.1/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./site.css" rel="stylesheet">
<title>container/list</title>
</head>
<body>
<div class="container">
<h2 id="pkg-overview">package list</h2>
<p><code>import "container/list"</code>
<p>list包实现了双向链表。要遍历一个链表:</p>
<pre>for e := l.Front(); e != nil; e = e.Next() {
// do something with e.Value
}</pre>
<div class="panel-group">
<div class="panel panel-default" id="example-package">
<div class="panel-heading" onclick="document.getElementById('ex-package').style.display = document.getElementById('ex-package').style.display=='none'?'block':'none';">Example</div>
<div id="ex-package" class="panel-collapse collapse">
<div class="panel-body">
<pre><span class="com">// Create a new list and put some numbers in it.</span>
l := list.New()
e4 := l.PushBack(4)
e1 := l.PushFront(1)
l.InsertBefore(3, e4)
l.InsertAfter(2, e1)
<span class="com">// Iterate through list and print its contents.</span>
for e := l.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}</pre>
<p>Output:
<pre>1
2
3
4
</pre>
</div>
</div>
</div>
</div>
<h3 id="pkg-index" class="section-header">Index <a class="permalink" href="#pkg-index">¶</a></h3>
<a href="../main.html"><h3>返回首页</h3></a>
</br>
<li><a href="#Element">type Element</a></li>
<ul>
<li><a href="#Element.Next">func (e *Element) Next() *Element</a></li>
<li><a href="#Element.Prev">func (e *Element) Prev() *Element</a></li>
</ul>
<li><a href="#List">type List</a></li>
<ul>
<li><a href="#New">func New() *List</a></li>
<li><a href="#List.Init">func (l *List) Init() *List</a></li>
<li><a href="#List.Len">func (l *List) Len() int</a></li>
<li><a href="#List.Front">func (l *List) Front() *Element</a></li>
<li><a href="#List.Back">func (l *List) Back() *Element</a></li>
<li><a href="#List.PushFront">func (l *List) PushFront(v interface{}) *Element</a></li>
<li><a href="#List.PushFrontList">func (l *List) PushFrontList(other *List)</a></li>
<li><a href="#List.PushBack">func (l *List) PushBack(v interface{}) *Element</a></li>
<li><a href="#List.PushBackList">func (l *List) PushBackList(other *List)</a></li>
<li><a href="#List.InsertBefore">func (l *List) InsertBefore(v interface{}, mark *Element) *Element</a></li>
<li><a href="#List.InsertAfter">func (l *List) InsertAfter(v interface{}, mark *Element) *Element</a></li>
<li><a href="#List.MoveToFront">func (l *List) MoveToFront(e *Element)</a></li>
<li><a href="#List.MoveToBack">func (l *List) MoveToBack(e *Element)</a></li>
<li><a href="#List.MoveBefore">func (l *List) MoveBefore(e, mark *Element)</a></li>
<li><a href="#List.MoveAfter">func (l *List) MoveAfter(e, mark *Element)</a></li>
<li><a href="#List.Remove">func (l *List) Remove(e *Element) interface{}</a></li>
</ul>
</ul>
<h4 id="pkg-examples">Examples <a class="permalink" href="#pkg-index">¶</a></h4>
<a href="../main.html"><h3>返回首页</h3></a>
</br>
<li><a href="#example-package" onclick="$('#ex-package').addClass('in').removeClass('collapse').height('auto')">package</a></li>
</ul>
<h3 id="Element">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#15">Element</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre>type Element struct {
<span class="com">// 元素保管的值</span>
<span id="Element.Value">Value</span> interface{}
<span class="com">// 内含隐藏或非导出字段</span>
}</pre>
<p>Element类型代表是双向链表的一个元素。</p>
<h4 id="Element.Next">func (*Element) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#31">Next</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (e *<a href="#Element">Element</a>) Next() *<a href="#Element">Element</a></pre>
<p>Next返回链表的后一个元素或者nil。</p>
<h4 id="Element.Prev">func (*Element) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#39">Prev</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (e *<a href="#Element">Element</a>) Prev() *<a href="#Element">Element</a></pre>
<p>Prev返回链表的前一个元素或者nil。</p>
<h3 id="List">type <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#48">List</a> <a class="permalink" href="#pkg-index">¶</a></h3>
<pre>type List struct {
<span class="com">// 内含隐藏或非导出字段</span>
}</pre>
<p>List代表一个双向链表。List零值为一个空的、可用的链表。</p>
<h4 id="New">func <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#62">New</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func New() *<a href="#List">List</a></pre>
<p>New创建一个链表。</p>
<h4 id="List.Init">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#54">Init</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) Init() *<a href="#List">List</a></pre>
<p>Init清空链表。</p>
<h4 id="List.Len">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#66">Len</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) Len() <a href="builtin.htm#int">int</a></pre>
<p>Len返回链表中元素的个数,复杂度O(1)。</p>
<h4 id="List.Front">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#69">Front</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) Front() *<a href="#Element">Element</a></pre>
<p>Front返回链表第一个元素或nil。</p>
<h4 id="List.Back">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#77">Back</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) Back() *<a href="#Element">Element</a></pre>
<p>Back返回链表最后一个元素或nil。</p>
<h4 id="List.PushFront">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#131">PushFront</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) PushFront(v interface{}) *<a href="#Element">Element</a></pre>
<p>PushBack将一个值为v的新元素插入链表的第一个位置,返回生成的新元素。</p>
<h4 id="List.PushFrontList">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#211">PushFrontList</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) PushFrontList(other *<a href="#List">List</a>)</pre>
<p>PushFrontList创建链表other的拷贝,并将拷贝的最后一个位置连接到链表l的第一个位置。</p>
<h4 id="List.PushBack">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#137">PushBack</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) PushBack(v interface{}) *<a href="#Element">Element</a></pre>
<p>PushBack将一个值为v的新元素插入链表的最后一个位置,返回生成的新元素。</p>
<h4 id="List.PushBackList">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#202">PushBackList</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) PushBackList(other *<a href="#List">List</a>)</pre>
<p>PushBack创建链表other的拷贝,并将链表l的最后一个位置连接到拷贝的第一个位置。</p>
<h4 id="List.InsertBefore">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#144">InsertBefore</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) InsertBefore(v interface{}, mark *<a href="#Element">Element</a>) *<a href="#Element">Element</a></pre>
<p>InsertDefore将一个值为v的新元素插入到mark前面,并返回生成的新元素。如果mark不是l的元素,l不会被修改。</p>
<h4 id="List.InsertAfter">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#154">InsertAfter</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) InsertAfter(v interface{}, mark *<a href="#Element">Element</a>) *<a href="#Element">Element</a></pre>
<p>InsertAfter将一个值为v的新元素插入到mark后面,并返回新生成的元素。如果mark不是l的元素,l不会被修改。</p>
<h4 id="List.MoveToFront">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#164">MoveToFront</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) MoveToFront(e *<a href="#Element">Element</a>)</pre>
<p>MoveToFront将元素e移动到链表的第一个位置,如果e不是l的元素,l不会被修改。</p>
<h4 id="List.MoveToBack">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#174">MoveToBack</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) MoveToBack(e *<a href="#Element">Element</a>)</pre>
<p>MoveToBack将元素e移动到链表的最后一个位置,如果e不是l的元素,l不会被修改。</p>
<h4 id="List.MoveBefore">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#184">MoveBefore</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) MoveBefore(e, mark *<a href="#Element">Element</a>)</pre>
<p>MoveBefore将元素e移动到mark的前面。如果e或mark不是l的元素,或者e==mark,l不会被修改。</p>
<h4 id="List.MoveAfter">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#193">MoveAfter</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) MoveAfter(e, mark *<a href="#Element">Element</a>)</pre>
<p>MoveAfter将元素e移动到mark的后面。如果e或mark不是l的元素,或者e==mark,l不会被修改。</p>
<h4 id="List.Remove">func (*List) <a title="View Source" href="https://github.com/golang/go/blob/master/src/container/list/list.go?name=release#121">Remove</a> <a class="permalink" href="#pkg-index">¶</a></h4>
<pre class="funcdecl">func (l *<a href="#List">List</a>) Remove(e *<a href="#Element">Element</a>) interface{}</pre>
<p>Remove删除链表中的元素e,并返回e.Value。</p>
</div>
</body>
</html>