grosser-algorithms 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +45 -0
- data/VERSION +1 -0
- data/ext/containers/bst/bst.c +249 -0
- data/ext/containers/bst/extconf.rb +4 -0
- data/grosser-algorithms.gemspec +4 -4
- data/rdoc/classes/Algorithms.html +221 -0
- data/rdoc/classes/Algorithms/Algorithms.html +115 -0
- data/rdoc/classes/Algorithms/Algorithms/Sort.html +569 -0
- data/rdoc/classes/Algorithms/Containers.html +162 -0
- data/rdoc/classes/Algorithms/Containers/Heap.html +690 -0
- data/rdoc/classes/Algorithms/Containers/KDTree.html +195 -0
- data/rdoc/classes/Algorithms/Containers/MaxHeap.html +238 -0
- data/rdoc/classes/Algorithms/Containers/MinHeap.html +238 -0
- data/rdoc/classes/Algorithms/Containers/PriorityQueue.html +456 -0
- data/rdoc/classes/Algorithms/Containers/Queue.html +363 -0
- data/rdoc/classes/Algorithms/Containers/RubyDeque.html +617 -0
- data/rdoc/classes/Algorithms/Containers/RubyRBTreeMap.html +662 -0
- data/rdoc/classes/Algorithms/Containers/RubySplayTreeMap.html +623 -0
- data/rdoc/classes/Algorithms/Containers/Stack.html +363 -0
- data/rdoc/classes/Algorithms/Containers/SuffixArray.html +246 -0
- data/rdoc/classes/Algorithms/Containers/Trie.html +555 -0
- data/rdoc/classes/Algorithms/Search.html +273 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/History_txt.html +281 -0
- data/rdoc/files/README_markdown.html +248 -0
- data/rdoc/files/lib/algorithms/search_rb.html +108 -0
- data/rdoc/files/lib/algorithms/sort_rb.html +108 -0
- data/rdoc/files/lib/algorithms/string_rb.html +115 -0
- data/rdoc/files/lib/algorithms_rb.html +252 -0
- data/rdoc/files/lib/containers/deque_rb.html +119 -0
- data/rdoc/files/lib/containers/heap_rb.html +124 -0
- data/rdoc/files/lib/containers/kd_tree_rb.html +135 -0
- data/rdoc/files/lib/containers/priority_queue_rb.html +108 -0
- data/rdoc/files/lib/containers/queue_rb.html +108 -0
- data/rdoc/files/lib/containers/rb_tree_map_rb.html +109 -0
- data/rdoc/files/lib/containers/splay_tree_map_rb.html +109 -0
- data/rdoc/files/lib/containers/stack_rb.html +108 -0
- data/rdoc/files/lib/containers/suffix_array_rb.html +113 -0
- data/rdoc/files/lib/containers/trie_rb.html +117 -0
- data/rdoc/fr_class_index.html +43 -0
- data/rdoc/fr_file_index.html +42 -0
- data/rdoc/fr_method_index.html +147 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/spec/bst_gc_mark_spec.rb +25 -0
- data/spec/bst_spec.rb +25 -0
- metadata +50 -3
@@ -0,0 +1,363 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Algorithms::Containers::Queue</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Algorithms::Containers::Queue</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/containers/queue_rb.html">
|
59
|
+
lib/containers/queue.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000099"><<</a>
|
90
|
+
<a href="#M000103">each</a>
|
91
|
+
<a href="#M000102">empty?</a>
|
92
|
+
<a href="#M000096">new</a>
|
93
|
+
<a href="#M000097">next</a>
|
94
|
+
<a href="#M000100">pop</a>
|
95
|
+
<a href="#M000098">push</a>
|
96
|
+
<a href="#M000101">size</a>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
<!-- if includes -->
|
104
|
+
<div id="includes">
|
105
|
+
<h3 class="section-bar">Included Modules</h3>
|
106
|
+
|
107
|
+
<div id="includes-list">
|
108
|
+
<span class="include-name">Enumerable</span>
|
109
|
+
</div>
|
110
|
+
</div>
|
111
|
+
|
112
|
+
<div id="section">
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<!-- if method_list -->
|
122
|
+
<div id="methods">
|
123
|
+
<h3 class="section-bar">Public Class methods</h3>
|
124
|
+
|
125
|
+
<div id="method-M000096" class="method-detail">
|
126
|
+
<a name="M000096"></a>
|
127
|
+
|
128
|
+
<div class="method-heading">
|
129
|
+
<a href="#M000096" class="method-signature">
|
130
|
+
<span class="method-name">new</span><span class="method-args">(ary=[])</span>
|
131
|
+
</a>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
<div class="method-description">
|
135
|
+
<p>
|
136
|
+
Create a <a href="Queue.html#M000096">new</a> queue. Takes an optional
|
137
|
+
array argument to initialize the queue.
|
138
|
+
</p>
|
139
|
+
<pre>
|
140
|
+
q = Algorithms::Containers::Queue.new([1, 2, 3])
|
141
|
+
q.pop #=> 1
|
142
|
+
q.pop #=> 2
|
143
|
+
</pre>
|
144
|
+
<p><a class="source-toggle" href="#"
|
145
|
+
onclick="toggleCode('M000096-source');return false;">[Source]</a></p>
|
146
|
+
<div class="method-source-code" id="M000096-source">
|
147
|
+
<pre>
|
148
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 19</span>
|
149
|
+
19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">ary</span>=[])
|
150
|
+
20: <span class="ruby-ivar">@container</span> = <span class="ruby-constant">Deque</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ary</span>)
|
151
|
+
21: <span class="ruby-keyword kw">end</span>
|
152
|
+
</pre>
|
153
|
+
</div>
|
154
|
+
</div>
|
155
|
+
</div>
|
156
|
+
|
157
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
158
|
+
|
159
|
+
<div id="method-M000099" class="method-detail">
|
160
|
+
<a name="M000099"></a>
|
161
|
+
|
162
|
+
<div class="method-heading">
|
163
|
+
<span class="method-name"><<</span><span class="method-args">(obj)</span>
|
164
|
+
</div>
|
165
|
+
|
166
|
+
<div class="method-description">
|
167
|
+
<p>
|
168
|
+
Alias for <a href="Queue.html#M000098">push</a>
|
169
|
+
</p>
|
170
|
+
</div>
|
171
|
+
</div>
|
172
|
+
|
173
|
+
<div id="method-M000103" class="method-detail">
|
174
|
+
<a name="M000103"></a>
|
175
|
+
|
176
|
+
<div class="method-heading">
|
177
|
+
<a href="#M000103" class="method-signature">
|
178
|
+
<span class="method-name">each</span><span class="method-args">(&block)</span>
|
179
|
+
</a>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
<div class="method-description">
|
183
|
+
<p>
|
184
|
+
Iterate over the <a href="Queue.html">Queue</a> in FIFO order.
|
185
|
+
</p>
|
186
|
+
<p><a class="source-toggle" href="#"
|
187
|
+
onclick="toggleCode('M000103-source');return false;">[Source]</a></p>
|
188
|
+
<div class="method-source-code" id="M000103-source">
|
189
|
+
<pre>
|
190
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 66</span>
|
191
|
+
66: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
192
|
+
67: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">each_forward</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
193
|
+
68: <span class="ruby-keyword kw">end</span>
|
194
|
+
</pre>
|
195
|
+
</div>
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
|
199
|
+
<div id="method-M000102" class="method-detail">
|
200
|
+
<a name="M000102"></a>
|
201
|
+
|
202
|
+
<div class="method-heading">
|
203
|
+
<a href="#M000102" class="method-signature">
|
204
|
+
<span class="method-name">empty?</span><span class="method-args">()</span>
|
205
|
+
</a>
|
206
|
+
</div>
|
207
|
+
|
208
|
+
<div class="method-description">
|
209
|
+
<p>
|
210
|
+
Returns true if the queue is empty, false otherwise.
|
211
|
+
</p>
|
212
|
+
<p><a class="source-toggle" href="#"
|
213
|
+
onclick="toggleCode('M000102-source');return false;">[Source]</a></p>
|
214
|
+
<div class="method-source-code" id="M000102-source">
|
215
|
+
<pre>
|
216
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 61</span>
|
217
|
+
61: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
|
218
|
+
62: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">empty?</span>
|
219
|
+
63: <span class="ruby-keyword kw">end</span>
|
220
|
+
</pre>
|
221
|
+
</div>
|
222
|
+
</div>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
<div id="method-M000097" class="method-detail">
|
226
|
+
<a name="M000097"></a>
|
227
|
+
|
228
|
+
<div class="method-heading">
|
229
|
+
<a href="#M000097" class="method-signature">
|
230
|
+
<span class="method-name">next</span><span class="method-args">()</span>
|
231
|
+
</a>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
<div class="method-description">
|
235
|
+
<p>
|
236
|
+
Returns the <a href="Queue.html#M000097">next</a> item from the queue but
|
237
|
+
does not remove it.
|
238
|
+
</p>
|
239
|
+
<pre>
|
240
|
+
q = Algorithms::Containers::Queue.new([1, 2, 3])
|
241
|
+
q.next #=> 1
|
242
|
+
q.size #=> 3
|
243
|
+
</pre>
|
244
|
+
<p><a class="source-toggle" href="#"
|
245
|
+
onclick="toggleCode('M000097-source');return false;">[Source]</a></p>
|
246
|
+
<div class="method-source-code" id="M000097-source">
|
247
|
+
<pre>
|
248
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 28</span>
|
249
|
+
28: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
|
250
|
+
29: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">front</span>
|
251
|
+
30: <span class="ruby-keyword kw">end</span>
|
252
|
+
</pre>
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
</div>
|
256
|
+
|
257
|
+
<div id="method-M000100" class="method-detail">
|
258
|
+
<a name="M000100"></a>
|
259
|
+
|
260
|
+
<div class="method-heading">
|
261
|
+
<a href="#M000100" class="method-signature">
|
262
|
+
<span class="method-name">pop</span><span class="method-args">()</span>
|
263
|
+
</a>
|
264
|
+
</div>
|
265
|
+
|
266
|
+
<div class="method-description">
|
267
|
+
<p>
|
268
|
+
Removes the <a href="Queue.html#M000097">next</a> item from the queue and
|
269
|
+
returns it.
|
270
|
+
</p>
|
271
|
+
<pre>
|
272
|
+
q = Algorithms::Containers::Queue.new([1, 2, 3])
|
273
|
+
q.pop #=> 1
|
274
|
+
q.size #=> 2
|
275
|
+
</pre>
|
276
|
+
<p><a class="source-toggle" href="#"
|
277
|
+
onclick="toggleCode('M000100-source');return false;">[Source]</a></p>
|
278
|
+
<div class="method-source-code" id="M000100-source">
|
279
|
+
<pre>
|
280
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 48</span>
|
281
|
+
48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop</span>
|
282
|
+
49: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">pop_front</span>
|
283
|
+
50: <span class="ruby-keyword kw">end</span>
|
284
|
+
</pre>
|
285
|
+
</div>
|
286
|
+
</div>
|
287
|
+
</div>
|
288
|
+
|
289
|
+
<div id="method-M000098" class="method-detail">
|
290
|
+
<a name="M000098"></a>
|
291
|
+
|
292
|
+
<div class="method-heading">
|
293
|
+
<a href="#M000098" class="method-signature">
|
294
|
+
<span class="method-name">push</span><span class="method-args">(obj)</span>
|
295
|
+
</a>
|
296
|
+
</div>
|
297
|
+
|
298
|
+
<div class="method-description">
|
299
|
+
<p>
|
300
|
+
Adds an item to the queue.
|
301
|
+
</p>
|
302
|
+
<pre>
|
303
|
+
q = Algorithms::Containers::Queue.new([1])
|
304
|
+
q.push(2)
|
305
|
+
q.pop #=> 1
|
306
|
+
q.pop #=> 2
|
307
|
+
</pre>
|
308
|
+
<p><a class="source-toggle" href="#"
|
309
|
+
onclick="toggleCode('M000098-source');return false;">[Source]</a></p>
|
310
|
+
<div class="method-source-code" id="M000098-source">
|
311
|
+
<pre>
|
312
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 38</span>
|
313
|
+
38: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push</span>(<span class="ruby-identifier">obj</span>)
|
314
|
+
39: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">push_back</span>(<span class="ruby-identifier">obj</span>)
|
315
|
+
40: <span class="ruby-keyword kw">end</span>
|
316
|
+
</pre>
|
317
|
+
</div>
|
318
|
+
</div>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
<div id="method-M000101" class="method-detail">
|
322
|
+
<a name="M000101"></a>
|
323
|
+
|
324
|
+
<div class="method-heading">
|
325
|
+
<a href="#M000101" class="method-signature">
|
326
|
+
<span class="method-name">size</span><span class="method-args">()</span>
|
327
|
+
</a>
|
328
|
+
</div>
|
329
|
+
|
330
|
+
<div class="method-description">
|
331
|
+
<p>
|
332
|
+
Return the number of items in the queue.
|
333
|
+
</p>
|
334
|
+
<pre>
|
335
|
+
q = Algorithms::Containers::Queue.new([1, 2, 3])
|
336
|
+
q.size #=> 3
|
337
|
+
</pre>
|
338
|
+
<p><a class="source-toggle" href="#"
|
339
|
+
onclick="toggleCode('M000101-source');return false;">[Source]</a></p>
|
340
|
+
<div class="method-source-code" id="M000101-source">
|
341
|
+
<pre>
|
342
|
+
<span class="ruby-comment cmt"># File lib/containers/queue.rb, line 56</span>
|
343
|
+
56: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
|
344
|
+
57: <span class="ruby-ivar">@container</span>.<span class="ruby-identifier">size</span>
|
345
|
+
58: <span class="ruby-keyword kw">end</span>
|
346
|
+
</pre>
|
347
|
+
</div>
|
348
|
+
</div>
|
349
|
+
</div>
|
350
|
+
|
351
|
+
|
352
|
+
</div>
|
353
|
+
|
354
|
+
|
355
|
+
</div>
|
356
|
+
|
357
|
+
|
358
|
+
<div id="validator-badges">
|
359
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
360
|
+
</div>
|
361
|
+
|
362
|
+
</body>
|
363
|
+
</html>
|
@@ -0,0 +1,617 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Algorithms::Containers::RubyDeque</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Algorithms::Containers::RubyDeque</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/containers/deque_rb.html">
|
59
|
+
lib/containers/deque.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000071">back</a>
|
90
|
+
<a href="#M000067">clear</a>
|
91
|
+
<a href="#M000077">each</a>
|
92
|
+
<a href="#M000078">each_backward</a>
|
93
|
+
<a href="#M000076">each_forward</a>
|
94
|
+
<a href="#M000066">empty?</a>
|
95
|
+
<a href="#M000070">front</a>
|
96
|
+
<a href="#M000069">length</a>
|
97
|
+
<a href="#M000065">new</a>
|
98
|
+
<a href="#M000075">pop_back</a>
|
99
|
+
<a href="#M000074">pop_front</a>
|
100
|
+
<a href="#M000073">push_back</a>
|
101
|
+
<a href="#M000072">push_front</a>
|
102
|
+
<a href="#M000079">reverse_each</a>
|
103
|
+
<a href="#M000068">size</a>
|
104
|
+
</div>
|
105
|
+
</div>
|
106
|
+
|
107
|
+
</div>
|
108
|
+
|
109
|
+
|
110
|
+
<!-- if includes -->
|
111
|
+
<div id="includes">
|
112
|
+
<h3 class="section-bar">Included Modules</h3>
|
113
|
+
|
114
|
+
<div id="includes-list">
|
115
|
+
<span class="include-name">Enumerable</span>
|
116
|
+
</div>
|
117
|
+
</div>
|
118
|
+
|
119
|
+
<div id="section">
|
120
|
+
|
121
|
+
|
122
|
+
<div id="constants-list">
|
123
|
+
<h3 class="section-bar">Constants</h3>
|
124
|
+
|
125
|
+
<div class="name-list">
|
126
|
+
<table summary="Constants">
|
127
|
+
<tr class="top-aligned-row context-row">
|
128
|
+
<td class="context-item-name">Node</td>
|
129
|
+
<td>=</td>
|
130
|
+
<td class="context-item-value">Struct.new(:left, :right, :obj)</td>
|
131
|
+
</tr>
|
132
|
+
</table>
|
133
|
+
</div>
|
134
|
+
</div>
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<!-- if method_list -->
|
142
|
+
<div id="methods">
|
143
|
+
<h3 class="section-bar">Public Class methods</h3>
|
144
|
+
|
145
|
+
<div id="method-M000065" class="method-detail">
|
146
|
+
<a name="M000065"></a>
|
147
|
+
|
148
|
+
<div class="method-heading">
|
149
|
+
<a href="#M000065" class="method-signature">
|
150
|
+
<span class="method-name">new</span><span class="method-args">(ary=[])</span>
|
151
|
+
</a>
|
152
|
+
</div>
|
153
|
+
|
154
|
+
<div class="method-description">
|
155
|
+
<p>
|
156
|
+
Create a <a href="RubyDeque.html#M000065">new</a> Deque. Takes an optional
|
157
|
+
array argument to initialize the Deque.
|
158
|
+
</p>
|
159
|
+
<pre>
|
160
|
+
d = Containers::Deque.new([1, 2, 3])
|
161
|
+
d.front #=> 1
|
162
|
+
d.back #=> 3
|
163
|
+
</pre>
|
164
|
+
<p><a class="source-toggle" href="#"
|
165
|
+
onclick="toggleCode('M000065-source');return false;">[Source]</a></p>
|
166
|
+
<div class="method-source-code" id="M000065-source">
|
167
|
+
<pre>
|
168
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 19</span>
|
169
|
+
19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">ary</span>=[])
|
170
|
+
20: <span class="ruby-ivar">@front</span> = <span class="ruby-keyword kw">nil</span>
|
171
|
+
21: <span class="ruby-ivar">@back</span> = <span class="ruby-keyword kw">nil</span>
|
172
|
+
22: <span class="ruby-ivar">@size</span> = <span class="ruby-value">0</span>
|
173
|
+
23: <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">push_back</span>(<span class="ruby-identifier">obj</span>) }
|
174
|
+
24: <span class="ruby-keyword kw">end</span>
|
175
|
+
</pre>
|
176
|
+
</div>
|
177
|
+
</div>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
181
|
+
|
182
|
+
<div id="method-M000071" class="method-detail">
|
183
|
+
<a name="M000071"></a>
|
184
|
+
|
185
|
+
<div class="method-heading">
|
186
|
+
<a href="#M000071" class="method-signature">
|
187
|
+
<span class="method-name">back</span><span class="method-args">()</span>
|
188
|
+
</a>
|
189
|
+
</div>
|
190
|
+
|
191
|
+
<div class="method-description">
|
192
|
+
<p>
|
193
|
+
Returns the object at the <a href="RubyDeque.html#M000071">back</a> of the
|
194
|
+
Deque but does not remove it.
|
195
|
+
</p>
|
196
|
+
<pre>
|
197
|
+
d = Containers::Deque.new
|
198
|
+
d.push_front(1)
|
199
|
+
d.push_front(2)
|
200
|
+
d.back #=> 1
|
201
|
+
</pre>
|
202
|
+
<p><a class="source-toggle" href="#"
|
203
|
+
onclick="toggleCode('M000071-source');return false;">[Source]</a></p>
|
204
|
+
<div class="method-source-code" id="M000071-source">
|
205
|
+
<pre>
|
206
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 62</span>
|
207
|
+
62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">back</span>
|
208
|
+
63: <span class="ruby-ivar">@back</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@back</span>.<span class="ruby-identifier">obj</span>
|
209
|
+
64: <span class="ruby-keyword kw">end</span>
|
210
|
+
</pre>
|
211
|
+
</div>
|
212
|
+
</div>
|
213
|
+
</div>
|
214
|
+
|
215
|
+
<div id="method-M000067" class="method-detail">
|
216
|
+
<a name="M000067"></a>
|
217
|
+
|
218
|
+
<div class="method-heading">
|
219
|
+
<a href="#M000067" class="method-signature">
|
220
|
+
<span class="method-name">clear</span><span class="method-args">()</span>
|
221
|
+
</a>
|
222
|
+
</div>
|
223
|
+
|
224
|
+
<div class="method-description">
|
225
|
+
<p>
|
226
|
+
Removes all the objects in the Deque.
|
227
|
+
</p>
|
228
|
+
<p><a class="source-toggle" href="#"
|
229
|
+
onclick="toggleCode('M000067-source');return false;">[Source]</a></p>
|
230
|
+
<div class="method-source-code" id="M000067-source">
|
231
|
+
<pre>
|
232
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 32</span>
|
233
|
+
32: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear</span>
|
234
|
+
33: <span class="ruby-ivar">@front</span> = <span class="ruby-ivar">@back</span> = <span class="ruby-keyword kw">nil</span>
|
235
|
+
34: <span class="ruby-ivar">@size</span> = <span class="ruby-value">0</span>
|
236
|
+
35: <span class="ruby-keyword kw">end</span>
|
237
|
+
</pre>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
</div>
|
241
|
+
|
242
|
+
<div id="method-M000077" class="method-detail">
|
243
|
+
<a name="M000077"></a>
|
244
|
+
|
245
|
+
<div class="method-heading">
|
246
|
+
<span class="method-name">each</span><span class="method-args">()</span>
|
247
|
+
</div>
|
248
|
+
|
249
|
+
<div class="method-description">
|
250
|
+
<p>
|
251
|
+
Alias for <a href="RubyDeque.html#M000076">each_forward</a>
|
252
|
+
</p>
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
|
256
|
+
<div id="method-M000078" class="method-detail">
|
257
|
+
<a name="M000078"></a>
|
258
|
+
|
259
|
+
<div class="method-heading">
|
260
|
+
<a href="#M000078" class="method-signature">
|
261
|
+
<span class="method-name">each_backward</span><span class="method-args">() {|node.obj| ...}</span>
|
262
|
+
</a>
|
263
|
+
</div>
|
264
|
+
|
265
|
+
<div class="method-description">
|
266
|
+
<p>
|
267
|
+
Iterate over the Deque in LIFO order.
|
268
|
+
</p>
|
269
|
+
<p><a class="source-toggle" href="#"
|
270
|
+
onclick="toggleCode('M000078-source');return false;">[Source]</a></p>
|
271
|
+
<div class="method-source-code" id="M000078-source">
|
272
|
+
<pre>
|
273
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 156</span>
|
274
|
+
156: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each_backward</span>
|
275
|
+
157: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@back</span>
|
276
|
+
158: <span class="ruby-identifier">node</span> = <span class="ruby-ivar">@back</span>
|
277
|
+
159: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">node</span>
|
278
|
+
160: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
279
|
+
161: <span class="ruby-identifier">node</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">left</span>
|
280
|
+
162: <span class="ruby-keyword kw">end</span>
|
281
|
+
163: <span class="ruby-keyword kw">end</span>
|
282
|
+
</pre>
|
283
|
+
</div>
|
284
|
+
</div>
|
285
|
+
</div>
|
286
|
+
|
287
|
+
<div id="method-M000076" class="method-detail">
|
288
|
+
<a name="M000076"></a>
|
289
|
+
|
290
|
+
<div class="method-heading">
|
291
|
+
<a href="#M000076" class="method-signature">
|
292
|
+
<span class="method-name">each_forward</span><span class="method-args">() {|node.obj| ...}</span>
|
293
|
+
</a>
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div class="method-description">
|
297
|
+
<p>
|
298
|
+
Iterate over the Deque in FIFO order.
|
299
|
+
</p>
|
300
|
+
<p><a class="source-toggle" href="#"
|
301
|
+
onclick="toggleCode('M000076-source');return false;">[Source]</a></p>
|
302
|
+
<div class="method-source-code" id="M000076-source">
|
303
|
+
<pre>
|
304
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 145</span>
|
305
|
+
145: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each_forward</span>
|
306
|
+
146: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@front</span>
|
307
|
+
147: <span class="ruby-identifier">node</span> = <span class="ruby-ivar">@front</span>
|
308
|
+
148: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">node</span>
|
309
|
+
149: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
310
|
+
150: <span class="ruby-identifier">node</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">right</span>
|
311
|
+
151: <span class="ruby-keyword kw">end</span>
|
312
|
+
152: <span class="ruby-keyword kw">end</span>
|
313
|
+
</pre>
|
314
|
+
</div>
|
315
|
+
</div>
|
316
|
+
</div>
|
317
|
+
|
318
|
+
<div id="method-M000066" class="method-detail">
|
319
|
+
<a name="M000066"></a>
|
320
|
+
|
321
|
+
<div class="method-heading">
|
322
|
+
<a href="#M000066" class="method-signature">
|
323
|
+
<span class="method-name">empty?</span><span class="method-args">()</span>
|
324
|
+
</a>
|
325
|
+
</div>
|
326
|
+
|
327
|
+
<div class="method-description">
|
328
|
+
<p>
|
329
|
+
Returns true if the Deque is empty, false otherwise.
|
330
|
+
</p>
|
331
|
+
<p><a class="source-toggle" href="#"
|
332
|
+
onclick="toggleCode('M000066-source');return false;">[Source]</a></p>
|
333
|
+
<div class="method-source-code" id="M000066-source">
|
334
|
+
<pre>
|
335
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 27</span>
|
336
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">empty?</span>
|
337
|
+
28: <span class="ruby-ivar">@size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
338
|
+
29: <span class="ruby-keyword kw">end</span>
|
339
|
+
</pre>
|
340
|
+
</div>
|
341
|
+
</div>
|
342
|
+
</div>
|
343
|
+
|
344
|
+
<div id="method-M000070" class="method-detail">
|
345
|
+
<a name="M000070"></a>
|
346
|
+
|
347
|
+
<div class="method-heading">
|
348
|
+
<a href="#M000070" class="method-signature">
|
349
|
+
<span class="method-name">front</span><span class="method-args">()</span>
|
350
|
+
</a>
|
351
|
+
</div>
|
352
|
+
|
353
|
+
<div class="method-description">
|
354
|
+
<p>
|
355
|
+
Returns the object at the <a href="RubyDeque.html#M000070">front</a> of the
|
356
|
+
Deque but does not remove it.
|
357
|
+
</p>
|
358
|
+
<pre>
|
359
|
+
d = Containers::Deque.new
|
360
|
+
d.push_front(1)
|
361
|
+
d.push_front(2)
|
362
|
+
d.front #=> 2
|
363
|
+
</pre>
|
364
|
+
<p><a class="source-toggle" href="#"
|
365
|
+
onclick="toggleCode('M000070-source');return false;">[Source]</a></p>
|
366
|
+
<div class="method-source-code" id="M000070-source">
|
367
|
+
<pre>
|
368
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 52</span>
|
369
|
+
52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">front</span>
|
370
|
+
53: <span class="ruby-ivar">@front</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@front</span>.<span class="ruby-identifier">obj</span>
|
371
|
+
54: <span class="ruby-keyword kw">end</span>
|
372
|
+
</pre>
|
373
|
+
</div>
|
374
|
+
</div>
|
375
|
+
</div>
|
376
|
+
|
377
|
+
<div id="method-M000069" class="method-detail">
|
378
|
+
<a name="M000069"></a>
|
379
|
+
|
380
|
+
<div class="method-heading">
|
381
|
+
<span class="method-name">length</span><span class="method-args">()</span>
|
382
|
+
</div>
|
383
|
+
|
384
|
+
<div class="method-description">
|
385
|
+
<p>
|
386
|
+
Alias for <a href="RubyDeque.html#M000068">size</a>
|
387
|
+
</p>
|
388
|
+
</div>
|
389
|
+
</div>
|
390
|
+
|
391
|
+
<div id="method-M000075" class="method-detail">
|
392
|
+
<a name="M000075"></a>
|
393
|
+
|
394
|
+
<div class="method-heading">
|
395
|
+
<a href="#M000075" class="method-signature">
|
396
|
+
<span class="method-name">pop_back</span><span class="method-args">()</span>
|
397
|
+
</a>
|
398
|
+
</div>
|
399
|
+
|
400
|
+
<div class="method-description">
|
401
|
+
<p>
|
402
|
+
Returns the object at the <a href="RubyDeque.html#M000071">back</a> of the
|
403
|
+
Deque and removes it.
|
404
|
+
</p>
|
405
|
+
<pre>
|
406
|
+
d = Containers::Deque.new
|
407
|
+
d.push_front(1)
|
408
|
+
d.push_front(2)
|
409
|
+
d.pop_back #=> 1
|
410
|
+
d.size #=> 1
|
411
|
+
</pre>
|
412
|
+
<p><a class="source-toggle" href="#"
|
413
|
+
onclick="toggleCode('M000075-source');return false;">[Source]</a></p>
|
414
|
+
<div class="method-source-code" id="M000075-source">
|
415
|
+
<pre>
|
416
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 130</span>
|
417
|
+
130: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop_back</span>
|
418
|
+
131: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@back</span>
|
419
|
+
132: <span class="ruby-identifier">node</span> = <span class="ruby-ivar">@back</span>
|
420
|
+
133: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
|
421
|
+
134: <span class="ruby-identifier">clear</span>
|
422
|
+
135: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
423
|
+
136: <span class="ruby-keyword kw">else</span>
|
424
|
+
137: <span class="ruby-ivar">@back</span>.<span class="ruby-identifier">left</span>.<span class="ruby-identifier">right</span> = <span class="ruby-keyword kw">nil</span>
|
425
|
+
138: <span class="ruby-ivar">@back</span> = <span class="ruby-ivar">@back</span>.<span class="ruby-identifier">left</span>
|
426
|
+
139: <span class="ruby-keyword kw">end</span>
|
427
|
+
140: <span class="ruby-ivar">@size</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
428
|
+
141: <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
429
|
+
142: <span class="ruby-keyword kw">end</span>
|
430
|
+
</pre>
|
431
|
+
</div>
|
432
|
+
</div>
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<div id="method-M000074" class="method-detail">
|
436
|
+
<a name="M000074"></a>
|
437
|
+
|
438
|
+
<div class="method-heading">
|
439
|
+
<a href="#M000074" class="method-signature">
|
440
|
+
<span class="method-name">pop_front</span><span class="method-args">()</span>
|
441
|
+
</a>
|
442
|
+
</div>
|
443
|
+
|
444
|
+
<div class="method-description">
|
445
|
+
<p>
|
446
|
+
Returns the object at the <a href="RubyDeque.html#M000070">front</a> of the
|
447
|
+
Deque and removes it.
|
448
|
+
</p>
|
449
|
+
<pre>
|
450
|
+
d = Containers::Deque.new
|
451
|
+
d.push_front(1)
|
452
|
+
d.push_front(2)
|
453
|
+
d.pop_front #=> 2
|
454
|
+
d.size #=> 1
|
455
|
+
</pre>
|
456
|
+
<p><a class="source-toggle" href="#"
|
457
|
+
onclick="toggleCode('M000074-source');return false;">[Source]</a></p>
|
458
|
+
<div class="method-source-code" id="M000074-source">
|
459
|
+
<pre>
|
460
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 109</span>
|
461
|
+
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pop_front</span>
|
462
|
+
110: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@front</span>
|
463
|
+
111: <span class="ruby-identifier">node</span> = <span class="ruby-ivar">@front</span>
|
464
|
+
112: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
|
465
|
+
113: <span class="ruby-identifier">clear</span>
|
466
|
+
114: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
467
|
+
115: <span class="ruby-keyword kw">else</span>
|
468
|
+
116: <span class="ruby-ivar">@front</span>.<span class="ruby-identifier">right</span>.<span class="ruby-identifier">left</span> = <span class="ruby-keyword kw">nil</span>
|
469
|
+
117: <span class="ruby-ivar">@front</span> = <span class="ruby-ivar">@front</span>.<span class="ruby-identifier">right</span>
|
470
|
+
118: <span class="ruby-keyword kw">end</span>
|
471
|
+
119: <span class="ruby-ivar">@size</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
472
|
+
120: <span class="ruby-identifier">node</span>.<span class="ruby-identifier">obj</span>
|
473
|
+
121: <span class="ruby-keyword kw">end</span>
|
474
|
+
</pre>
|
475
|
+
</div>
|
476
|
+
</div>
|
477
|
+
</div>
|
478
|
+
|
479
|
+
<div id="method-M000073" class="method-detail">
|
480
|
+
<a name="M000073"></a>
|
481
|
+
|
482
|
+
<div class="method-heading">
|
483
|
+
<a href="#M000073" class="method-signature">
|
484
|
+
<span class="method-name">push_back</span><span class="method-args">(obj)</span>
|
485
|
+
</a>
|
486
|
+
</div>
|
487
|
+
|
488
|
+
<div class="method-description">
|
489
|
+
<p>
|
490
|
+
Adds an object at the <a href="RubyDeque.html#M000071">back</a> of the
|
491
|
+
Deque.
|
492
|
+
</p>
|
493
|
+
<pre>
|
494
|
+
d = Containers::Deque.new([1, 2, 3])
|
495
|
+
d.push_back(4)
|
496
|
+
d.pop_back #=> 4
|
497
|
+
</pre>
|
498
|
+
<p><a class="source-toggle" href="#"
|
499
|
+
onclick="toggleCode('M000073-source');return false;">[Source]</a></p>
|
500
|
+
<div class="method-source-code" id="M000073-source">
|
501
|
+
<pre>
|
502
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 89</span>
|
503
|
+
89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push_back</span>(<span class="ruby-identifier">obj</span>)
|
504
|
+
90: <span class="ruby-identifier">node</span> = <span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">obj</span>)
|
505
|
+
91: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@back</span>
|
506
|
+
92: <span class="ruby-identifier">node</span>.<span class="ruby-identifier">left</span> = <span class="ruby-ivar">@back</span>
|
507
|
+
93: <span class="ruby-ivar">@back</span>.<span class="ruby-identifier">right</span> = <span class="ruby-identifier">node</span>
|
508
|
+
94: <span class="ruby-ivar">@back</span> = <span class="ruby-identifier">node</span>
|
509
|
+
95: <span class="ruby-keyword kw">else</span>
|
510
|
+
96: <span class="ruby-ivar">@front</span> = <span class="ruby-ivar">@back</span> = <span class="ruby-identifier">node</span>
|
511
|
+
97: <span class="ruby-keyword kw">end</span>
|
512
|
+
98: <span class="ruby-ivar">@size</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
513
|
+
99: <span class="ruby-identifier">obj</span>
|
514
|
+
100: <span class="ruby-keyword kw">end</span>
|
515
|
+
</pre>
|
516
|
+
</div>
|
517
|
+
</div>
|
518
|
+
</div>
|
519
|
+
|
520
|
+
<div id="method-M000072" class="method-detail">
|
521
|
+
<a name="M000072"></a>
|
522
|
+
|
523
|
+
<div class="method-heading">
|
524
|
+
<a href="#M000072" class="method-signature">
|
525
|
+
<span class="method-name">push_front</span><span class="method-args">(obj)</span>
|
526
|
+
</a>
|
527
|
+
</div>
|
528
|
+
|
529
|
+
<div class="method-description">
|
530
|
+
<p>
|
531
|
+
Adds an object at the <a href="RubyDeque.html#M000070">front</a> of the
|
532
|
+
Deque.
|
533
|
+
</p>
|
534
|
+
<pre>
|
535
|
+
d = Containers::Deque.new([1, 2, 3])
|
536
|
+
d.push_front(0)
|
537
|
+
d.pop_front #=> 0
|
538
|
+
</pre>
|
539
|
+
<p><a class="source-toggle" href="#"
|
540
|
+
onclick="toggleCode('M000072-source');return false;">[Source]</a></p>
|
541
|
+
<div class="method-source-code" id="M000072-source">
|
542
|
+
<pre>
|
543
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 71</span>
|
544
|
+
71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">push_front</span>(<span class="ruby-identifier">obj</span>)
|
545
|
+
72: <span class="ruby-identifier">node</span> = <span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">obj</span>)
|
546
|
+
73: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@front</span>
|
547
|
+
74: <span class="ruby-identifier">node</span>.<span class="ruby-identifier">right</span> = <span class="ruby-ivar">@front</span>
|
548
|
+
75: <span class="ruby-ivar">@front</span>.<span class="ruby-identifier">left</span> = <span class="ruby-identifier">node</span>
|
549
|
+
76: <span class="ruby-ivar">@front</span> = <span class="ruby-identifier">node</span>
|
550
|
+
77: <span class="ruby-keyword kw">else</span>
|
551
|
+
78: <span class="ruby-ivar">@front</span> = <span class="ruby-ivar">@back</span> = <span class="ruby-identifier">node</span>
|
552
|
+
79: <span class="ruby-keyword kw">end</span>
|
553
|
+
80: <span class="ruby-ivar">@size</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
554
|
+
81: <span class="ruby-identifier">obj</span>
|
555
|
+
82: <span class="ruby-keyword kw">end</span>
|
556
|
+
</pre>
|
557
|
+
</div>
|
558
|
+
</div>
|
559
|
+
</div>
|
560
|
+
|
561
|
+
<div id="method-M000079" class="method-detail">
|
562
|
+
<a name="M000079"></a>
|
563
|
+
|
564
|
+
<div class="method-heading">
|
565
|
+
<span class="method-name">reverse_each</span><span class="method-args">()</span>
|
566
|
+
</div>
|
567
|
+
|
568
|
+
<div class="method-description">
|
569
|
+
<p>
|
570
|
+
Alias for <a href="RubyDeque.html#M000078">each_backward</a>
|
571
|
+
</p>
|
572
|
+
</div>
|
573
|
+
</div>
|
574
|
+
|
575
|
+
<div id="method-M000068" class="method-detail">
|
576
|
+
<a name="M000068"></a>
|
577
|
+
|
578
|
+
<div class="method-heading">
|
579
|
+
<a href="#M000068" class="method-signature">
|
580
|
+
<span class="method-name">size</span><span class="method-args">()</span>
|
581
|
+
</a>
|
582
|
+
</div>
|
583
|
+
|
584
|
+
<div class="method-description">
|
585
|
+
<p>
|
586
|
+
Return the number of items in the Deque.
|
587
|
+
</p>
|
588
|
+
<pre>
|
589
|
+
d = Containers::Deque.new([1, 2, 3])
|
590
|
+
d.size #=> 3
|
591
|
+
</pre>
|
592
|
+
<p><a class="source-toggle" href="#"
|
593
|
+
onclick="toggleCode('M000068-source');return false;">[Source]</a></p>
|
594
|
+
<div class="method-source-code" id="M000068-source">
|
595
|
+
<pre>
|
596
|
+
<span class="ruby-comment cmt"># File lib/containers/deque.rb, line 41</span>
|
597
|
+
41: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>
|
598
|
+
42: <span class="ruby-ivar">@size</span>
|
599
|
+
43: <span class="ruby-keyword kw">end</span>
|
600
|
+
</pre>
|
601
|
+
</div>
|
602
|
+
</div>
|
603
|
+
</div>
|
604
|
+
|
605
|
+
|
606
|
+
</div>
|
607
|
+
|
608
|
+
|
609
|
+
</div>
|
610
|
+
|
611
|
+
|
612
|
+
<div id="validator-badges">
|
613
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
614
|
+
</div>
|
615
|
+
|
616
|
+
</body>
|
617
|
+
</html>
|