ds 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +13 -0
  4. data/doc/Array.html +264 -0
  5. data/doc/DS.html +292 -0
  6. data/doc/DS/Array2D.html +345 -0
  7. data/doc/DS/BinaryHeap.html +493 -0
  8. data/doc/DS/BinarySearchTree.html +313 -0
  9. data/doc/DS/BinaryTree.html +433 -0
  10. data/doc/DS/CompleteBinaryTree.html +550 -0
  11. data/doc/DS/CyclicList.html +234 -0
  12. data/doc/DS/Digraph.html +299 -0
  13. data/doc/DS/Edge.html +283 -0
  14. data/doc/DS/ExpandableArray.html +316 -0
  15. data/doc/DS/Graph.html +739 -0
  16. data/doc/DS/GraphAsList.html +361 -0
  17. data/doc/DS/GraphAsMatrix.html +633 -0
  18. data/doc/DS/GraphAsTriMatrix.html +274 -0
  19. data/doc/DS/List.html +1263 -0
  20. data/doc/DS/ListElement.html +344 -0
  21. data/doc/DS/Queue.html +517 -0
  22. data/doc/DS/Ring.html +323 -0
  23. data/doc/DS/Stack.html +407 -0
  24. data/doc/DS/Tree.html +770 -0
  25. data/doc/DS/TreeWalker.html +561 -0
  26. data/doc/DS/TriMatrix.html +338 -0
  27. data/doc/created.rid +25 -0
  28. data/doc/ds/graphs/digraph_rb.html +52 -0
  29. data/doc/ds/graphs/edge_rb.html +52 -0
  30. data/doc/ds/graphs/graph_as_list_rb.html +52 -0
  31. data/doc/ds/graphs/graph_as_matrix_rb.html +52 -0
  32. data/doc/ds/graphs/graph_as_tri_matrix_rb.html +52 -0
  33. data/doc/ds/graphs/graph_rb.html +52 -0
  34. data/doc/ds/lists/cyclic_list_rb.html +52 -0
  35. data/doc/ds/lists/list_element_rb.html +52 -0
  36. data/doc/ds/lists/list_rb.html +52 -0
  37. data/doc/ds/lists/ring_rb.html +52 -0
  38. data/doc/ds/matrixes/array_2d_rb.html +52 -0
  39. data/doc/ds/matrixes/expandable_array_rb.html +52 -0
  40. data/doc/ds/matrixes/tri_matrix_rb.html +52 -0
  41. data/doc/ds/queues/queue_rb.html +52 -0
  42. data/doc/ds/stacks/stack_rb.html +52 -0
  43. data/doc/ds/trees/binary_heap_rb.html +52 -0
  44. data/doc/ds/trees/binary_search_tree_rb.html +52 -0
  45. data/doc/ds/trees/binary_tree_rb.html +52 -0
  46. data/doc/ds/trees/complete_binary_tree_rb.html +52 -0
  47. data/doc/ds/trees/tree_rb.html +52 -0
  48. data/doc/ds/trees/tree_walker_rb.html +52 -0
  49. data/doc/ds/version_rb.html +52 -0
  50. data/doc/ds_rb.html +98 -0
  51. data/doc/ext/ext_rb.html +52 -0
  52. data/doc/images/brick.png +0 -0
  53. data/doc/images/brick_link.png +0 -0
  54. data/doc/images/bug.png +0 -0
  55. data/doc/images/bullet_black.png +0 -0
  56. data/doc/images/bullet_toggle_minus.png +0 -0
  57. data/doc/images/bullet_toggle_plus.png +0 -0
  58. data/doc/images/date.png +0 -0
  59. data/doc/images/find.png +0 -0
  60. data/doc/images/loadingAnimation.gif +0 -0
  61. data/doc/images/macFFBgHack.png +0 -0
  62. data/doc/images/package.png +0 -0
  63. data/doc/images/page_green.png +0 -0
  64. data/doc/images/page_white_text.png +0 -0
  65. data/doc/images/page_white_width.png +0 -0
  66. data/doc/images/plugin.png +0 -0
  67. data/doc/images/ruby.png +0 -0
  68. data/doc/images/tag_green.png +0 -0
  69. data/doc/images/wrench.png +0 -0
  70. data/doc/images/wrench_orange.png +0 -0
  71. data/doc/images/zoom.png +0 -0
  72. data/doc/index.html +375 -0
  73. data/doc/js/darkfish.js +116 -0
  74. data/doc/js/jquery.js +32 -0
  75. data/doc/js/quicksearch.js +114 -0
  76. data/doc/js/thickbox-compressed.js +10 -0
  77. data/doc/rdoc.css +763 -0
  78. data/ds.gemspec +20 -0
  79. data/lib/ds.rb +38 -0
  80. data/lib/ds/graphs/digraph.rb +20 -0
  81. data/lib/ds/graphs/edge.rb +15 -0
  82. data/lib/ds/graphs/graph.rb +107 -0
  83. data/lib/ds/graphs/graph_as_list.rb +48 -0
  84. data/lib/ds/graphs/graph_as_matrix.rb +114 -0
  85. data/lib/ds/graphs/graph_as_tri_matrix.rb +25 -0
  86. data/lib/ds/lists/cyclic_list.rb +21 -0
  87. data/lib/ds/lists/list.rb +303 -0
  88. data/lib/ds/lists/list_element.rb +26 -0
  89. data/lib/ds/lists/ring.rb +42 -0
  90. data/lib/ds/matrixes/array_2d.rb +35 -0
  91. data/lib/ds/matrixes/expandable_array.rb +37 -0
  92. data/lib/ds/matrixes/tri_matrix.rb +30 -0
  93. data/lib/ds/queues/queue.rb +53 -0
  94. data/lib/ds/stacks/stack.rb +39 -0
  95. data/lib/ds/trees/binary_heap.rb +71 -0
  96. data/lib/ds/trees/binary_search_tree.rb +32 -0
  97. data/lib/ds/trees/binary_tree.rb +65 -0
  98. data/lib/ds/trees/complete_binary_tree.rb +52 -0
  99. data/lib/ds/trees/tree.rb +117 -0
  100. data/lib/ds/trees/tree_walker.rb +179 -0
  101. data/lib/ds/version.rb +3 -0
  102. data/lib/ext/ext.rb +15 -0
  103. data/test/help.rb +8 -0
  104. data/test/test_array2d.rb +51 -0
  105. data/test/test_binary_heap.rb +35 -0
  106. data/test/test_binary_search_tree.rb +32 -0
  107. data/test/test_binary_tree.rb +51 -0
  108. data/test/test_complete_binary_tree.rb +30 -0
  109. data/test/test_digraph.rb +134 -0
  110. data/test/test_expandable_array.rb +26 -0
  111. data/test/test_graph.rb +71 -0
  112. data/test/test_list.rb +138 -0
  113. data/test/test_list_element.rb +56 -0
  114. data/test/test_queue.rb +110 -0
  115. data/test/test_ring.rb +28 -0
  116. data/test/test_stack.rb +87 -0
  117. data/test/test_tree.rb +48 -0
  118. data/test/test_tree_walker.rb +69 -0
  119. data/test/test_tri_matrix.rb +22 -0
  120. metadata +184 -0
@@ -0,0 +1,274 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: DS::GraphAsTriMatrix</title>
9
+
10
+ <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
15
+ <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>
16
+
17
+ </head>
18
+ <body id="top" class="class">
19
+
20
+ <div id="metadata">
21
+ <div id="home-metadata">
22
+ <div id="home-section" class="section">
23
+ <h3 class="section-header">
24
+ <a href="../index.html">Home</a>
25
+ <a href="../index.html#classes">Classes</a>
26
+ <a href="../index.html#methods">Methods</a>
27
+ </h3>
28
+ </div>
29
+ </div>
30
+
31
+ <div id="file-metadata">
32
+ <div id="file-list-section" class="section">
33
+ <h3 class="section-header">In Files</h3>
34
+ <div class="section-body">
35
+ <ul>
36
+
37
+ <li><a href="../ds/graphs/graph_as_tri_matrix_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
38
+ class="thickbox" title="ds/graphs/graph_as_tri_matrix.rb">ds/graphs/graph_as_tri_matrix.rb</a></li>
39
+
40
+ </ul>
41
+ </div>
42
+ </div>
43
+
44
+
45
+ </div>
46
+
47
+ <div id="class-metadata">
48
+
49
+ <!-- Parent Class -->
50
+ <div id="parent-class-section" class="section">
51
+ <h3 class="section-header">Parent</h3>
52
+
53
+ <p class="link"><a href="GraphAsMatrix.html">DS::GraphAsMatrix</a></p>
54
+
55
+ </div>
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ <!-- Method Quickref -->
64
+ <div id="method-list-section" class="section">
65
+ <h3 class="section-header">Methods</h3>
66
+ <ul class="link-list">
67
+
68
+ <li><a href="#method-c-new">::new</a></li>
69
+
70
+ <li><a href="#method-i-degree">#degree</a></li>
71
+
72
+ </ul>
73
+ </div>
74
+
75
+
76
+
77
+ </div>
78
+
79
+ <div id="project-metadata">
80
+
81
+
82
+
83
+ <div id="classindex-section" class="section project-section">
84
+ <h3 class="section-header">Class/Module Index
85
+ <span class="search-toggle"><img src="../images/find.png"
86
+ height="16" width="16" alt="[+]"
87
+ title="show/hide quicksearch" /></span></h3>
88
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
89
+ <fieldset>
90
+ <legend>Quicksearch</legend>
91
+ <input type="text" name="quicksearch" value=""
92
+ class="quicksearch-field" />
93
+ </fieldset>
94
+ </form>
95
+
96
+ <ul class="link-list">
97
+
98
+ <li><a href="../DS.html">DS</a></li>
99
+
100
+ <li><a href="../DS/Array2D.html">DS::Array2D</a></li>
101
+
102
+ <li><a href="../DS/BinaryHeap.html">DS::BinaryHeap</a></li>
103
+
104
+ <li><a href="../DS/BinarySearchTree.html">DS::BinarySearchTree</a></li>
105
+
106
+ <li><a href="../DS/BinaryTree.html">DS::BinaryTree</a></li>
107
+
108
+ <li><a href="../DS/CompleteBinaryTree.html">DS::CompleteBinaryTree</a></li>
109
+
110
+ <li><a href="../DS/CyclicList.html">DS::CyclicList</a></li>
111
+
112
+ <li><a href="../DS/Digraph.html">DS::Digraph</a></li>
113
+
114
+ <li><a href="../DS/Edge.html">DS::Edge</a></li>
115
+
116
+ <li><a href="../DS/ExpandableArray.html">DS::ExpandableArray</a></li>
117
+
118
+ <li><a href="../DS/Graph.html">DS::Graph</a></li>
119
+
120
+ <li><a href="../DS/GraphAsList.html">DS::GraphAsList</a></li>
121
+
122
+ <li><a href="../DS/GraphAsMatrix.html">DS::GraphAsMatrix</a></li>
123
+
124
+ <li><a href="../DS/GraphAsTriMatrix.html">DS::GraphAsTriMatrix</a></li>
125
+
126
+ <li><a href="../DS/List.html">DS::List</a></li>
127
+
128
+ <li><a href="../DS/ListElement.html">DS::ListElement</a></li>
129
+
130
+ <li><a href="../DS/Queue.html">DS::Queue</a></li>
131
+
132
+ <li><a href="../DS/Ring.html">DS::Ring</a></li>
133
+
134
+ <li><a href="../DS/Stack.html">DS::Stack</a></li>
135
+
136
+ <li><a href="../DS/Tree.html">DS::Tree</a></li>
137
+
138
+ <li><a href="../DS/TreeWalker.html">DS::TreeWalker</a></li>
139
+
140
+ <li><a href="../DS/TriMatrix.html">DS::TriMatrix</a></li>
141
+
142
+ <li><a href="../Array.html">Array</a></li>
143
+
144
+ </ul>
145
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
146
+ </div>
147
+
148
+
149
+ </div>
150
+ </div>
151
+
152
+ <div id="documentation">
153
+ <h1 class="class">DS::GraphAsTriMatrix</h1>
154
+
155
+ <div id="description" class="description">
156
+
157
+ </div><!-- description -->
158
+
159
+
160
+
161
+
162
+ <div id="5Buntitled-5D" class="documentation-section">
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ <!-- Methods -->
172
+
173
+ <div id="public-class-method-details" class="method-section section">
174
+ <h3 class="section-header">Public Class Methods</h3>
175
+
176
+
177
+ <div id="new-method" class="method-detail ">
178
+ <a name="method-c-new"></a>
179
+
180
+
181
+ <div class="method-heading">
182
+ <span class="method-name">new</span><span
183
+ class="method-args">(edges)</span>
184
+ <span class="method-click-advice">click to toggle source</span>
185
+ </div>
186
+
187
+
188
+ <div class="method-description">
189
+
190
+
191
+
192
+
193
+
194
+ <div class="method-source-code" id="new-source">
195
+ <pre>
196
+ <span class="ruby-comment"># File ds/graphs/graph_as_tri_matrix.rb, line 4</span>
197
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">edges</span>)
198
+ <span class="ruby-ivar">@store</span> = <span class="ruby-constant">TriMatrix</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>)
199
+ <span class="ruby-ivar">@max</span> = <span class="ruby-value">0</span>
200
+ <span class="ruby-ivar">@map</span> = []
201
+ <span class="ruby-ivar">@v</span> = <span class="ruby-value">0</span>
202
+
203
+ <span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">edges</span>)
204
+ <span class="ruby-keyword">end</span></pre>
205
+ </div><!-- new-source -->
206
+
207
+ </div>
208
+
209
+
210
+
211
+
212
+ </div><!-- new-method -->
213
+
214
+
215
+ </div><!-- public-class-method-details -->
216
+
217
+ <div id="public-instance-method-details" class="method-section section">
218
+ <h3 class="section-header">Public Instance Methods</h3>
219
+
220
+
221
+ <div id="degree-method" class="method-detail ">
222
+ <a name="method-i-degree"></a>
223
+
224
+
225
+ <div class="method-heading">
226
+ <span class="method-name">degree</span><span
227
+ class="method-args">(x)</span>
228
+ <span class="method-click-advice">click to toggle source</span>
229
+ </div>
230
+
231
+
232
+ <div class="method-description">
233
+
234
+ <p>Returns vertex degree.</p>
235
+
236
+
237
+
238
+ <div class="method-source-code" id="degree-source">
239
+ <pre>
240
+ <span class="ruby-comment"># File ds/graphs/graph_as_tri_matrix.rb, line 14</span>
241
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">degree</span>(<span class="ruby-identifier">x</span>)
242
+ <span class="ruby-identifier">x</span> = <span class="ruby-ivar">@map</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">x</span>)
243
+ <span class="ruby-identifier">sum</span> = <span class="ruby-value">0</span>
244
+ <span class="ruby-value">0</span>.<span class="ruby-identifier">upto</span> <span class="ruby-ivar">@max</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
245
+ <span class="ruby-identifier">sum</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span>] <span class="ruby-keyword">if</span> <span class="ruby-ivar">@store</span>[<span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span>]
246
+ <span class="ruby-keyword">end</span>
247
+ <span class="ruby-identifier">sum</span>
248
+ <span class="ruby-keyword">end</span></pre>
249
+ </div><!-- degree-source -->
250
+
251
+ </div>
252
+
253
+
254
+
255
+
256
+ </div><!-- degree-method -->
257
+
258
+
259
+ </div><!-- public-instance-method-details -->
260
+
261
+ </div><!-- 5Buntitled-5D -->
262
+
263
+
264
+ </div><!-- documentation -->
265
+
266
+ <div id="validator-badges">
267
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
268
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
269
+ Rdoc Generator</a> 2</small>.</p>
270
+ </div>
271
+
272
+ </body>
273
+ </html>
274
+
@@ -0,0 +1,1263 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: DS::List</title>
9
+
10
+ <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
13
+ <script src="../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
14
+ <script src="../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
15
+ <script src="../js/darkfish.js" type="text/javascript" charset="utf-8"></script>
16
+
17
+ </head>
18
+ <body id="top" class="class">
19
+
20
+ <div id="metadata">
21
+ <div id="home-metadata">
22
+ <div id="home-section" class="section">
23
+ <h3 class="section-header">
24
+ <a href="../index.html">Home</a>
25
+ <a href="../index.html#classes">Classes</a>
26
+ <a href="../index.html#methods">Methods</a>
27
+ </h3>
28
+ </div>
29
+ </div>
30
+
31
+ <div id="file-metadata">
32
+ <div id="file-list-section" class="section">
33
+ <h3 class="section-header">In Files</h3>
34
+ <div class="section-body">
35
+ <ul>
36
+
37
+ <li><a href="../ds/lists/list_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
38
+ class="thickbox" title="ds/lists/list.rb">ds/lists/list.rb</a></li>
39
+
40
+ </ul>
41
+ </div>
42
+ </div>
43
+
44
+
45
+ </div>
46
+
47
+ <div id="class-metadata">
48
+
49
+ <!-- Parent Class -->
50
+ <div id="parent-class-section" class="section">
51
+ <h3 class="section-header">Parent</h3>
52
+
53
+ <p class="link">Object</p>
54
+
55
+ </div>
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ <!-- Method Quickref -->
64
+ <div id="method-list-section" class="section">
65
+ <h3 class="section-header">Methods</h3>
66
+ <ul class="link-list">
67
+
68
+ <li><a href="#method-c-from_array">::from_array</a></li>
69
+
70
+ <li><a href="#method-c-new">::new</a></li>
71
+
72
+ <li><a href="#method-i-3C-3C">#<<</a></li>
73
+
74
+ <li><a href="#method-i-append">#append</a></li>
75
+
76
+ <li><a href="#method-i-each">#each</a></li>
77
+
78
+ <li><a href="#method-i-each_with_index">#each_with_index</a></li>
79
+
80
+ <li><a href="#method-i-empty-3F">#empty?</a></li>
81
+
82
+ <li><a href="#method-i-first">#first</a></li>
83
+
84
+ <li><a href="#method-i-insert_after">#insert_after</a></li>
85
+
86
+ <li><a href="#method-i-insert_before">#insert_before</a></li>
87
+
88
+ <li><a href="#method-i-joint">#joint</a></li>
89
+
90
+ <li><a href="#method-i-last">#last</a></li>
91
+
92
+ <li><a href="#method-i-length">#length</a></li>
93
+
94
+ <li><a href="#method-i-looped-3F">#looped?</a></li>
95
+
96
+ <li><a href="#method-i-merge">#merge</a></li>
97
+
98
+ <li><a href="#method-i-orderize">#orderize</a></li>
99
+
100
+ <li><a href="#method-i-prepend">#prepend</a></li>
101
+
102
+ <li><a href="#method-i-print">#print</a></li>
103
+
104
+ <li><a href="#method-i-remove">#remove</a></li>
105
+
106
+ <li><a href="#method-i-remove-21">#remove!</a></li>
107
+
108
+ <li><a href="#method-i-reverse-21">#reverse!</a></li>
109
+
110
+ <li><a href="#method-i-shift">#shift</a></li>
111
+
112
+ <li><a href="#method-i-to_a">#to_a</a></li>
113
+
114
+ <li><a href="#method-i-zip-3F">#zip?</a></li>
115
+
116
+ </ul>
117
+ </div>
118
+
119
+
120
+
121
+ <!-- Included Modules -->
122
+ <div id="includes-section" class="section">
123
+ <h3 class="section-header">Included Modules</h3>
124
+ <ul class="link-list">
125
+
126
+
127
+ <li><span class="include">Enumerable</span></li>
128
+
129
+
130
+ </ul>
131
+ </div>
132
+
133
+ </div>
134
+
135
+ <div id="project-metadata">
136
+
137
+
138
+
139
+ <div id="classindex-section" class="section project-section">
140
+ <h3 class="section-header">Class/Module Index
141
+ <span class="search-toggle"><img src="../images/find.png"
142
+ height="16" width="16" alt="[+]"
143
+ title="show/hide quicksearch" /></span></h3>
144
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
145
+ <fieldset>
146
+ <legend>Quicksearch</legend>
147
+ <input type="text" name="quicksearch" value=""
148
+ class="quicksearch-field" />
149
+ </fieldset>
150
+ </form>
151
+
152
+ <ul class="link-list">
153
+
154
+ <li><a href="../DS.html">DS</a></li>
155
+
156
+ <li><a href="../DS/Array2D.html">DS::Array2D</a></li>
157
+
158
+ <li><a href="../DS/BinaryHeap.html">DS::BinaryHeap</a></li>
159
+
160
+ <li><a href="../DS/BinarySearchTree.html">DS::BinarySearchTree</a></li>
161
+
162
+ <li><a href="../DS/BinaryTree.html">DS::BinaryTree</a></li>
163
+
164
+ <li><a href="../DS/CompleteBinaryTree.html">DS::CompleteBinaryTree</a></li>
165
+
166
+ <li><a href="../DS/CyclicList.html">DS::CyclicList</a></li>
167
+
168
+ <li><a href="../DS/Digraph.html">DS::Digraph</a></li>
169
+
170
+ <li><a href="../DS/Edge.html">DS::Edge</a></li>
171
+
172
+ <li><a href="../DS/ExpandableArray.html">DS::ExpandableArray</a></li>
173
+
174
+ <li><a href="../DS/Graph.html">DS::Graph</a></li>
175
+
176
+ <li><a href="../DS/GraphAsList.html">DS::GraphAsList</a></li>
177
+
178
+ <li><a href="../DS/GraphAsMatrix.html">DS::GraphAsMatrix</a></li>
179
+
180
+ <li><a href="../DS/GraphAsTriMatrix.html">DS::GraphAsTriMatrix</a></li>
181
+
182
+ <li><a href="../DS/List.html">DS::List</a></li>
183
+
184
+ <li><a href="../DS/ListElement.html">DS::ListElement</a></li>
185
+
186
+ <li><a href="../DS/Queue.html">DS::Queue</a></li>
187
+
188
+ <li><a href="../DS/Ring.html">DS::Ring</a></li>
189
+
190
+ <li><a href="../DS/Stack.html">DS::Stack</a></li>
191
+
192
+ <li><a href="../DS/Tree.html">DS::Tree</a></li>
193
+
194
+ <li><a href="../DS/TreeWalker.html">DS::TreeWalker</a></li>
195
+
196
+ <li><a href="../DS/TriMatrix.html">DS::TriMatrix</a></li>
197
+
198
+ <li><a href="../Array.html">Array</a></li>
199
+
200
+ </ul>
201
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
202
+ </div>
203
+
204
+
205
+ </div>
206
+ </div>
207
+
208
+ <div id="documentation">
209
+ <h1 class="class">DS::List</h1>
210
+
211
+ <div id="description" class="description">
212
+
213
+ <p>Implements simple list data structure.</p>
214
+
215
+ </div><!-- description -->
216
+
217
+
218
+
219
+
220
+ <div id="5Buntitled-5D" class="documentation-section">
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+ <!-- Attributes -->
229
+ <div id="attribute-method-details" class="method-section section">
230
+ <h3 class="section-header">Attributes</h3>
231
+
232
+
233
+ <div id="head-attribute-method" class="method-detail">
234
+ <a name="head"></a>
235
+
236
+ <a name="head="></a>
237
+
238
+ <div class="method-heading attribute-method-heading">
239
+ <span class="method-name">head</span><span
240
+ class="attribute-access-type">[RW]</span>
241
+ </div>
242
+
243
+ <div class="method-description">
244
+
245
+
246
+
247
+ </div>
248
+ </div>
249
+
250
+ <div id="tail-attribute-method" class="method-detail">
251
+ <a name="tail"></a>
252
+
253
+ <a name="tail="></a>
254
+
255
+ <div class="method-heading attribute-method-heading">
256
+ <span class="method-name">tail</span><span
257
+ class="attribute-access-type">[RW]</span>
258
+ </div>
259
+
260
+ <div class="method-description">
261
+
262
+
263
+
264
+ </div>
265
+ </div>
266
+
267
+ </div><!-- attribute-method-details -->
268
+
269
+
270
+ <!-- Methods -->
271
+
272
+ <div id="public-class-method-details" class="method-section section">
273
+ <h3 class="section-header">Public Class Methods</h3>
274
+
275
+
276
+ <div id="from_array-method" class="method-detail ">
277
+ <a name="method-c-from_array"></a>
278
+
279
+
280
+ <div class="method-heading">
281
+ <span class="method-name">from_array</span><span
282
+ class="method-args">(arr)</span>
283
+ <span class="method-click-advice">click to toggle source</span>
284
+ </div>
285
+
286
+
287
+ <div class="method-description">
288
+
289
+ <p>Creates list from array.</p>
290
+
291
+
292
+
293
+ <div class="method-source-code" id="from_array-source">
294
+ <pre>
295
+ <span class="ruby-comment"># File ds/lists/list.rb, line 17</span>
296
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">from_array</span>(<span class="ruby-identifier">arr</span>)
297
+ <span class="ruby-identifier">list</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">arr</span>.<span class="ruby-identifier">shift</span>)
298
+ <span class="ruby-identifier">tail</span> = <span class="ruby-identifier">list</span>.<span class="ruby-identifier">head</span>
299
+ <span class="ruby-identifier">arr</span>.<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">tail</span> = <span class="ruby-identifier">tail</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">e</span>) }
300
+ <span class="ruby-identifier">list</span>.<span class="ruby-identifier">tail</span> = <span class="ruby-identifier">tail</span>
301
+ <span class="ruby-identifier">list</span>
302
+ <span class="ruby-keyword">end</span></pre>
303
+ </div><!-- from_array-source -->
304
+
305
+ </div>
306
+
307
+
308
+
309
+
310
+ </div><!-- from_array-method -->
311
+
312
+
313
+ <div id="new-method" class="method-detail ">
314
+ <a name="method-c-new"></a>
315
+
316
+
317
+ <div class="method-heading">
318
+ <span class="method-name">new</span><span
319
+ class="method-args">(x=nil)</span>
320
+ <span class="method-click-advice">click to toggle source</span>
321
+ </div>
322
+
323
+
324
+ <div class="method-description">
325
+
326
+ <p>Creates new list.</p>
327
+
328
+
329
+
330
+ <div class="method-source-code" id="new-source">
331
+ <pre>
332
+ <span class="ruby-comment"># File ds/lists/list.rb, line 11</span>
333
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">x</span>=<span class="ruby-keyword">nil</span>)
334
+ <span class="ruby-ivar">@head</span> = <span class="ruby-constant">ListElement</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>)
335
+ <span class="ruby-ivar">@tail</span> = <span class="ruby-ivar">@head</span>
336
+ <span class="ruby-keyword">end</span></pre>
337
+ </div><!-- new-source -->
338
+
339
+ </div>
340
+
341
+
342
+
343
+
344
+ </div><!-- new-method -->
345
+
346
+
347
+ </div><!-- public-class-method-details -->
348
+
349
+ <div id="public-instance-method-details" class="method-section section">
350
+ <h3 class="section-header">Public Instance Methods</h3>
351
+
352
+
353
+ <div id="3C-3C-method" class="method-detail method-alias">
354
+ <a name="method-i-3C-3C"></a>
355
+
356
+
357
+ <div class="method-heading">
358
+ <span class="method-name">&lt;&lt;</span><span
359
+ class="method-args">(x)</span>
360
+ <span class="method-click-advice">click to toggle source</span>
361
+ </div>
362
+
363
+
364
+ <div class="method-description">
365
+
366
+
367
+
368
+
369
+
370
+ </div>
371
+
372
+
373
+
374
+
375
+ <div class="aliases">
376
+ Alias for: <a href="List.html#method-i-append">append</a>
377
+ </div>
378
+
379
+ </div><!-- 3C-3C-method -->
380
+
381
+
382
+ <div id="append-method" class="method-detail ">
383
+ <a name="method-i-append"></a>
384
+
385
+
386
+ <div class="method-heading">
387
+ <span class="method-name">append</span><span
388
+ class="method-args">(x)</span>
389
+ <span class="method-click-advice">click to toggle source</span>
390
+ </div>
391
+
392
+
393
+ <div class="method-description">
394
+
395
+ <p>Appends new element to list.</p>
396
+
397
+
398
+
399
+ <div class="method-source-code" id="append-source">
400
+ <pre>
401
+ <span class="ruby-comment"># File ds/lists/list.rb, line 26</span>
402
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">append</span>(<span class="ruby-identifier">x</span>)
403
+ <span class="ruby-identifier">last_elem</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">tail</span>
404
+ <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">empty?</span>
405
+ <span class="ruby-ivar">@tail</span> = <span class="ruby-identifier">last_elem</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">x</span>)
406
+ <span class="ruby-keyword">else</span>
407
+ <span class="ruby-ivar">@head</span> = <span class="ruby-constant">ListElement</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>)
408
+ <span class="ruby-ivar">@tail</span> = <span class="ruby-ivar">@head</span>
409
+ <span class="ruby-keyword">end</span>
410
+ <span class="ruby-keyword">end</span></pre>
411
+ </div><!-- append-source -->
412
+
413
+ </div>
414
+
415
+
416
+ <div class="aliases">
417
+ Also aliased as: <a href="List.html#method-i-3C-3C">&lt;&lt;</a>
418
+ </div>
419
+
420
+
421
+
422
+ </div><!-- append-method -->
423
+
424
+
425
+ <div id="each-method" class="method-detail ">
426
+ <a name="method-i-each"></a>
427
+
428
+
429
+ <div class="method-heading">
430
+ <span class="method-name">each</span><span
431
+ class="method-args">()</span>
432
+ <span class="method-click-advice">click to toggle source</span>
433
+ </div>
434
+
435
+
436
+ <div class="method-description">
437
+
438
+ <p>Default list iterator.</p>
439
+
440
+
441
+
442
+ <div class="method-source-code" id="each-source">
443
+ <pre>
444
+ <span class="ruby-comment"># File ds/lists/list.rb, line 284</span>
445
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">each</span>
446
+ <span class="ruby-identifier">elem</span> = <span class="ruby-ivar">@head</span>
447
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">elem</span>
448
+ <span class="ruby-keyword">yield</span> <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">data</span>
449
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span>
450
+ <span class="ruby-keyword">end</span>
451
+ <span class="ruby-keyword">end</span></pre>
452
+ </div><!-- each-source -->
453
+
454
+ </div>
455
+
456
+
457
+
458
+
459
+ </div><!-- each-method -->
460
+
461
+
462
+ <div id="each_with_index-method" class="method-detail ">
463
+ <a name="method-i-each_with_index"></a>
464
+
465
+
466
+ <div class="method-heading">
467
+ <span class="method-name">each_with_index</span><span
468
+ class="method-args">()</span>
469
+ <span class="method-click-advice">click to toggle source</span>
470
+ </div>
471
+
472
+
473
+ <div class="method-description">
474
+
475
+
476
+
477
+
478
+
479
+ <div class="method-source-code" id="each_with_index-source">
480
+ <pre>
481
+ <span class="ruby-comment"># File ds/lists/list.rb, line 292</span>
482
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">each_with_index</span>
483
+ <span class="ruby-identifier">elem</span> = <span class="ruby-ivar">@head</span>
484
+ <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
485
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">elem</span>
486
+ <span class="ruby-keyword">yield</span> <span class="ruby-identifier">elem</span>,<span class="ruby-identifier">i</span>
487
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span>
488
+ <span class="ruby-identifier">i</span> = <span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
489
+ <span class="ruby-keyword">end</span>
490
+ <span class="ruby-keyword">end</span></pre>
491
+ </div><!-- each_with_index-source -->
492
+
493
+ </div>
494
+
495
+
496
+
497
+
498
+ </div><!-- each_with_index-method -->
499
+
500
+
501
+ <div id="empty-3F-method" class="method-detail ">
502
+ <a name="method-i-empty-3F"></a>
503
+
504
+
505
+ <div class="method-heading">
506
+ <span class="method-name">empty?</span><span
507
+ class="method-args">()</span>
508
+ <span class="method-click-advice">click to toggle source</span>
509
+ </div>
510
+
511
+
512
+ <div class="method-description">
513
+
514
+ <p>Checks if list is empty.</p>
515
+
516
+
517
+
518
+ <div class="method-source-code" id="empty-3F-source">
519
+ <pre>
520
+ <span class="ruby-comment"># File ds/lists/list.rb, line 119</span>
521
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">empty?</span>
522
+ <span class="ruby-identifier">head</span>.<span class="ruby-identifier">data</span>.<span class="ruby-identifier">nil?</span>
523
+ <span class="ruby-keyword">end</span></pre>
524
+ </div><!-- empty-3F-source -->
525
+
526
+ </div>
527
+
528
+
529
+
530
+
531
+ </div><!-- empty-3F-method -->
532
+
533
+
534
+ <div id="first-method" class="method-detail ">
535
+ <a name="method-i-first"></a>
536
+
537
+
538
+ <div class="method-heading">
539
+ <span class="method-name">first</span><span
540
+ class="method-args">()</span>
541
+ <span class="method-click-advice">click to toggle source</span>
542
+ </div>
543
+
544
+
545
+ <div class="method-description">
546
+
547
+
548
+
549
+
550
+
551
+ <div class="method-source-code" id="first-source">
552
+ <pre>
553
+ <span class="ruby-comment"># File ds/lists/list.rb, line 128</span>
554
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">first</span>
555
+ <span class="ruby-identifier">head</span>.<span class="ruby-identifier">data</span>
556
+ <span class="ruby-keyword">end</span></pre>
557
+ </div><!-- first-source -->
558
+
559
+ </div>
560
+
561
+
562
+
563
+
564
+ </div><!-- first-method -->
565
+
566
+
567
+ <div id="insert_after-method" class="method-detail ">
568
+ <a name="method-i-insert_after"></a>
569
+
570
+
571
+ <div class="method-heading">
572
+ <span class="method-name">insert_after</span><span
573
+ class="method-args">(x,rel)</span>
574
+ <span class="method-click-advice">click to toggle source</span>
575
+ </div>
576
+
577
+
578
+ <div class="method-description">
579
+
580
+ <p>Inserts element x after another element.</p>
581
+
582
+
583
+
584
+ <div class="method-source-code" id="insert_after-source">
585
+ <pre>
586
+ <span class="ruby-comment"># File ds/lists/list.rb, line 72</span>
587
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">insert_after</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">rel</span>)
588
+ <span class="ruby-identifier">x</span> = <span class="ruby-constant">ListElement</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>)
589
+
590
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">head</span>
591
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">el</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">el</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">rel</span>
592
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
593
+ <span class="ruby-keyword">end</span>
594
+
595
+ <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Element not found&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">el</span>
596
+
597
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
598
+ <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">x</span>
599
+
600
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">tail?</span>
601
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">tail</span> = <span class="ruby-identifier">x</span>
602
+ <span class="ruby-keyword">end</span>
603
+ <span class="ruby-keyword">end</span></pre>
604
+ </div><!-- insert_after-source -->
605
+
606
+ </div>
607
+
608
+
609
+
610
+
611
+ </div><!-- insert_after-method -->
612
+
613
+
614
+ <div id="insert_before-method" class="method-detail ">
615
+ <a name="method-i-insert_before"></a>
616
+
617
+
618
+ <div class="method-heading">
619
+ <span class="method-name">insert_before</span><span
620
+ class="method-args">(x,rel)</span>
621
+ <span class="method-click-advice">click to toggle source</span>
622
+ </div>
623
+
624
+
625
+ <div class="method-description">
626
+
627
+ <p>Inserts element x before another element.</p>
628
+
629
+
630
+
631
+ <div class="method-source-code" id="insert_before-source">
632
+ <pre>
633
+ <span class="ruby-comment"># File ds/lists/list.rb, line 91</span>
634
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">insert_before</span>(<span class="ruby-identifier">x</span>,<span class="ruby-identifier">rel</span>)
635
+ <span class="ruby-identifier">x</span> = <span class="ruby-constant">ListElement</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>)
636
+
637
+ <span class="ruby-comment">#inserting at the beginnig of the list </span>
638
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">rel</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">head</span>
639
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">head</span>
640
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span> = <span class="ruby-identifier">x</span>
641
+
642
+ <span class="ruby-comment">#inserting in the tail of the list</span>
643
+ <span class="ruby-keyword">else</span>
644
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">head</span>
645
+ <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">head</span>
646
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">el</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">el</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">rel</span>
647
+ <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">el</span>
648
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
649
+ <span class="ruby-keyword">end</span>
650
+
651
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">el</span>.<span class="ruby-identifier">nil?</span>
652
+ <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;List element not found&quot;</span>
653
+ <span class="ruby-keyword">else</span>
654
+ <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">x</span>
655
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">el</span>
656
+ <span class="ruby-keyword">end</span>
657
+ <span class="ruby-keyword">end</span>
658
+ <span class="ruby-keyword">end</span></pre>
659
+ </div><!-- insert_before-source -->
660
+
661
+ </div>
662
+
663
+
664
+
665
+
666
+ </div><!-- insert_before-method -->
667
+
668
+
669
+ <div id="joint-method" class="method-detail ">
670
+ <a name="method-i-joint"></a>
671
+
672
+
673
+ <div class="method-heading">
674
+ <span class="method-name">joint</span><span
675
+ class="method-args">()</span>
676
+ <span class="method-click-advice">click to toggle source</span>
677
+ </div>
678
+
679
+
680
+ <div class="method-description">
681
+
682
+ <p>Returns joint element if exists, otherwise returns nil.</p>
683
+
684
+
685
+
686
+ <div class="method-source-code" id="joint-source">
687
+ <pre>
688
+ <span class="ruby-comment"># File ds/lists/list.rb, line 143</span>
689
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">joint</span>
690
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">head</span>
691
+ <span class="ruby-identifier">elem2</span> = <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span>
692
+
693
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">elem</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">elem2</span>
694
+
695
+ <span class="ruby-comment">#traversing by 1</span>
696
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span>
697
+
698
+ <span class="ruby-comment">#traversing by 2</span>
699
+ <span class="ruby-identifier">elem2</span> = <span class="ruby-identifier">elem2</span>.<span class="ruby-identifier">next</span>
700
+ <span class="ruby-identifier">elem2</span> = <span class="ruby-identifier">elem2</span>.<span class="ruby-identifier">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">elem2</span>
701
+
702
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">elem2</span>.<span class="ruby-identifier">equal?</span> <span class="ruby-identifier">elem</span>
703
+ <span class="ruby-keyword">return</span> <span class="ruby-identifier">elem</span>
704
+ <span class="ruby-keyword">end</span>
705
+ <span class="ruby-keyword">end</span>
706
+
707
+ <span class="ruby-keyword">nil</span>
708
+ <span class="ruby-keyword">end</span></pre>
709
+ </div><!-- joint-source -->
710
+
711
+ </div>
712
+
713
+
714
+
715
+
716
+ </div><!-- joint-method -->
717
+
718
+
719
+ <div id="last-method" class="method-detail ">
720
+ <a name="method-i-last"></a>
721
+
722
+
723
+ <div class="method-heading">
724
+ <span class="method-name">last</span><span
725
+ class="method-args">()</span>
726
+ <span class="method-click-advice">click to toggle source</span>
727
+ </div>
728
+
729
+
730
+ <div class="method-description">
731
+
732
+ <p>Returns last element of the list.</p>
733
+
734
+
735
+
736
+ <div class="method-source-code" id="last-source">
737
+ <pre>
738
+ <span class="ruby-comment"># File ds/lists/list.rb, line 124</span>
739
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">last</span>
740
+ <span class="ruby-identifier">tail</span>.<span class="ruby-identifier">data</span>
741
+ <span class="ruby-keyword">end</span></pre>
742
+ </div><!-- last-source -->
743
+
744
+ </div>
745
+
746
+
747
+
748
+
749
+ </div><!-- last-method -->
750
+
751
+
752
+ <div id="length-method" class="method-detail ">
753
+ <a name="method-i-length"></a>
754
+
755
+
756
+ <div class="method-heading">
757
+ <span class="method-name">length</span><span
758
+ class="method-args">()</span>
759
+ <span class="method-click-advice">click to toggle source</span>
760
+ </div>
761
+
762
+
763
+ <div class="method-description">
764
+
765
+ <p>Returns length of the list.</p>
766
+
767
+
768
+
769
+ <div class="method-source-code" id="length-source">
770
+ <pre>
771
+ <span class="ruby-comment"># File ds/lists/list.rb, line 133</span>
772
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">length</span>
773
+ <span class="ruby-identifier">count</span>
774
+ <span class="ruby-keyword">end</span></pre>
775
+ </div><!-- length-source -->
776
+
777
+ </div>
778
+
779
+
780
+
781
+
782
+ </div><!-- length-method -->
783
+
784
+
785
+ <div id="looped-3F-method" class="method-detail ">
786
+ <a name="method-i-looped-3F"></a>
787
+
788
+
789
+ <div class="method-heading">
790
+ <span class="method-name">looped?</span><span
791
+ class="method-args">()</span>
792
+ <span class="method-click-advice">click to toggle source</span>
793
+ </div>
794
+
795
+
796
+ <div class="method-description">
797
+
798
+ <p>Returns true if list has cycle.</p>
799
+
800
+
801
+
802
+ <div class="method-source-code" id="looped-3F-source">
803
+ <pre>
804
+ <span class="ruby-comment"># File ds/lists/list.rb, line 165</span>
805
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">looped?</span>
806
+ <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">joint</span>
807
+ <span class="ruby-keyword">end</span></pre>
808
+ </div><!-- looped-3F-source -->
809
+
810
+ </div>
811
+
812
+
813
+
814
+
815
+ </div><!-- looped-3F-method -->
816
+
817
+
818
+ <div id="merge-method" class="method-detail ">
819
+ <a name="method-i-merge"></a>
820
+
821
+
822
+ <div class="method-heading">
823
+ <span class="method-name">merge</span><span
824
+ class="method-args">(other)</span>
825
+ <span class="method-click-advice">click to toggle source</span>
826
+ </div>
827
+
828
+
829
+ <div class="method-description">
830
+
831
+ <p>Merge list with other list.</p>
832
+
833
+
834
+
835
+ <div class="method-source-code" id="merge-source">
836
+ <pre>
837
+ <span class="ruby-comment"># File ds/lists/list.rb, line 223</span>
838
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">merge</span>(<span class="ruby-identifier">other</span>)
839
+
840
+ <span class="ruby-identifier">a</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span>
841
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">head</span>
842
+
843
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span>
844
+ <span class="ruby-identifier">result</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span>)
845
+ <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">next</span>
846
+ <span class="ruby-keyword">else</span>
847
+ <span class="ruby-identifier">result</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span>)
848
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">next</span>
849
+ <span class="ruby-keyword">end</span>
850
+
851
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">a</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">b</span>
852
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span>
853
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span>)
854
+ <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">next</span>
855
+ <span class="ruby-keyword">else</span>
856
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span>)
857
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">next</span>
858
+ <span class="ruby-keyword">end</span>
859
+ <span class="ruby-keyword">end</span>
860
+ <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">b</span>
861
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">tail</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">a</span>
862
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">tail</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">tail</span>
863
+ <span class="ruby-keyword">elsif</span> <span class="ruby-operator">!</span><span class="ruby-identifier">a</span>
864
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">tail</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">b</span>
865
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">tail</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">tail</span>
866
+ <span class="ruby-keyword">end</span>
867
+ <span class="ruby-identifier">result</span>
868
+ <span class="ruby-keyword">end</span></pre>
869
+ </div><!-- merge-source -->
870
+
871
+ </div>
872
+
873
+
874
+
875
+
876
+ </div><!-- merge-method -->
877
+
878
+
879
+ <div id="orderize-method" class="method-detail ">
880
+ <a name="method-i-orderize"></a>
881
+
882
+
883
+ <div class="method-heading">
884
+ <span class="method-name">orderize</span><span
885
+ class="method-args">()</span>
886
+ <span class="method-click-advice">click to toggle source</span>
887
+ </div>
888
+
889
+
890
+ <div class="method-description">
891
+
892
+ <p>Orderize list by evaluating block. Block should evaluate to one of these
893
+ values: 1,0,-1 (same as Comparable).</p>
894
+
895
+
896
+
897
+ <div class="method-source-code" id="orderize-source">
898
+ <pre>
899
+ <span class="ruby-comment"># File ds/lists/list.rb, line 172</span>
900
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">orderize</span>
901
+
902
+ <span class="ruby-identifier">zero</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>
903
+ <span class="ruby-identifier">plus</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>
904
+ <span class="ruby-identifier">minus</span> = <span class="ruby-constant">List</span>.<span class="ruby-identifier">new</span>
905
+
906
+ <span class="ruby-identifier">el</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span>
907
+
908
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">el</span>
909
+ <span class="ruby-keyword">case</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">el</span>.<span class="ruby-identifier">data</span>
910
+ <span class="ruby-keyword">when</span> <span class="ruby-value">0</span>
911
+ <span class="ruby-identifier">zero_tail</span> = <span class="ruby-identifier">zero</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">el</span>.<span class="ruby-identifier">data</span>)
912
+ <span class="ruby-keyword">when</span> <span class="ruby-value">1</span>
913
+ <span class="ruby-identifier">plus_tail</span> = <span class="ruby-identifier">plus</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">el</span>.<span class="ruby-identifier">data</span>)
914
+ <span class="ruby-keyword">when</span> <span class="ruby-value">-1</span>
915
+ <span class="ruby-identifier">minus_tail</span> = <span class="ruby-identifier">minus</span>.<span class="ruby-identifier">append</span>(<span class="ruby-identifier">el</span>.<span class="ruby-identifier">data</span>)
916
+ <span class="ruby-keyword">end</span>
917
+
918
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
919
+ <span class="ruby-keyword">end</span>
920
+
921
+ <span class="ruby-identifier">minus_tail</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">zero</span>.<span class="ruby-identifier">head</span>
922
+ <span class="ruby-identifier">zero_tail</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">plus</span>.<span class="ruby-identifier">head</span>
923
+ <span class="ruby-keyword">return</span> <span class="ruby-identifier">minus</span>
924
+ <span class="ruby-keyword">end</span></pre>
925
+ </div><!-- orderize-source -->
926
+
927
+ </div>
928
+
929
+
930
+
931
+
932
+ </div><!-- orderize-method -->
933
+
934
+
935
+ <div id="prepend-method" class="method-detail ">
936
+ <a name="method-i-prepend"></a>
937
+
938
+
939
+ <div class="method-heading">
940
+ <span class="method-name">prepend</span><span
941
+ class="method-args">(x)</span>
942
+ <span class="method-click-advice">click to toggle source</span>
943
+ </div>
944
+
945
+
946
+ <div class="method-description">
947
+
948
+ <p>Prepends new element to list.</p>
949
+
950
+
951
+
952
+ <div class="method-source-code" id="prepend-source">
953
+ <pre>
954
+ <span class="ruby-comment"># File ds/lists/list.rb, line 39</span>
955
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">prepend</span>(<span class="ruby-identifier">x</span>)
956
+ <span class="ruby-identifier">el</span> = <span class="ruby-constant">ListElement</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">x</span>)
957
+ <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span> = <span class="ruby-ivar">@head</span>
958
+ <span class="ruby-ivar">@head</span> = <span class="ruby-identifier">el</span>
959
+ <span class="ruby-keyword">end</span></pre>
960
+ </div><!-- prepend-source -->
961
+
962
+ </div>
963
+
964
+
965
+
966
+
967
+ </div><!-- prepend-method -->
968
+
969
+
970
+ <div id="print-method" class="method-detail ">
971
+ <a name="method-i-print"></a>
972
+
973
+
974
+ <div class="method-heading">
975
+ <span class="method-name">print</span><span
976
+ class="method-args">()</span>
977
+ <span class="method-click-advice">click to toggle source</span>
978
+ </div>
979
+
980
+
981
+ <div class="method-description">
982
+
983
+ <p>Prints list.</p>
984
+
985
+
986
+
987
+ <div class="method-source-code" id="print-source">
988
+ <pre>
989
+ <span class="ruby-comment"># File ds/lists/list.rb, line 274</span>
990
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">print</span>
991
+ <span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> }
992
+ <span class="ruby-keyword">end</span></pre>
993
+ </div><!-- print-source -->
994
+
995
+ </div>
996
+
997
+
998
+
999
+
1000
+ </div><!-- print-method -->
1001
+
1002
+
1003
+ <div id="remove-method" class="method-detail ">
1004
+ <a name="method-i-remove"></a>
1005
+
1006
+
1007
+ <div class="method-heading">
1008
+ <span class="method-name">remove</span><span
1009
+ class="method-args">(x)</span>
1010
+ <span class="method-click-advice">click to toggle source</span>
1011
+ </div>
1012
+
1013
+
1014
+ <div class="method-description">
1015
+
1016
+ <p>Removes element x from list.</p>
1017
+
1018
+
1019
+
1020
+ <div class="method-source-code" id="remove-source">
1021
+ <pre>
1022
+ <span class="ruby-comment"># File ds/lists/list.rb, line 46</span>
1023
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">x</span>)
1024
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">x</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">head</span>
1025
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span> = <span class="ruby-identifier">head</span>.<span class="ruby-identifier">next</span>
1026
+ <span class="ruby-identifier">x</span>.<span class="ruby-identifier">next</span> = <span class="ruby-keyword">nil</span>
1027
+ <span class="ruby-keyword">else</span>
1028
+
1029
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">head</span>
1030
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">el</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">el</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">x</span>
1031
+ <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">el</span>
1032
+ <span class="ruby-identifier">el</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
1033
+ <span class="ruby-keyword">end</span>
1034
+
1035
+ <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Element not found&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">el</span>
1036
+
1037
+ <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span>
1038
+ <span class="ruby-identifier">el</span>.<span class="ruby-identifier">next</span> = <span class="ruby-keyword">nil</span>
1039
+ <span class="ruby-keyword">end</span>
1040
+ <span class="ruby-identifier">x</span>
1041
+ <span class="ruby-keyword">end</span></pre>
1042
+ </div><!-- remove-source -->
1043
+
1044
+ </div>
1045
+
1046
+
1047
+
1048
+
1049
+ </div><!-- remove-method -->
1050
+
1051
+
1052
+ <div id="remove-21-method" class="method-detail ">
1053
+ <a name="method-i-remove-21"></a>
1054
+
1055
+
1056
+ <div class="method-heading">
1057
+ <span class="method-name">remove!</span><span
1058
+ class="method-args">(other)</span>
1059
+ <span class="method-click-advice">click to toggle source</span>
1060
+ </div>
1061
+
1062
+
1063
+ <div class="method-description">
1064
+
1065
+ <p>Removes elements that exists on the other list.</p>
1066
+
1067
+
1068
+
1069
+ <div class="method-source-code" id="remove-21-source">
1070
+ <pre>
1071
+ <span class="ruby-comment"># File ds/lists/list.rb, line 200</span>
1072
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">remove!</span>(<span class="ruby-identifier">other</span>)
1073
+ <span class="ruby-identifier">a</span> = <span class="ruby-identifier">head</span>
1074
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">other</span>.<span class="ruby-identifier">head</span>
1075
+
1076
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">a</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">b</span>
1077
+
1078
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span>
1079
+ <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">a</span>
1080
+ <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">next</span>
1081
+ <span class="ruby-keyword">end</span>
1082
+
1083
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">data</span>
1084
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">next</span>
1085
+ <span class="ruby-keyword">end</span>
1086
+
1087
+ <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">next</span>
1088
+ <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">a</span>
1089
+ <span class="ruby-identifier">b</span> = <span class="ruby-identifier">b</span>.<span class="ruby-identifier">next</span>
1090
+ <span class="ruby-keyword">end</span>
1091
+ <span class="ruby-keyword">self</span>
1092
+ <span class="ruby-keyword">end</span></pre>
1093
+ </div><!-- remove-21-source -->
1094
+
1095
+ </div>
1096
+
1097
+
1098
+
1099
+
1100
+ </div><!-- remove-21-method -->
1101
+
1102
+
1103
+ <div id="reverse-21-method" class="method-detail ">
1104
+ <a name="method-i-reverse-21"></a>
1105
+
1106
+
1107
+ <div class="method-heading">
1108
+ <span class="method-name">reverse!</span><span
1109
+ class="method-args">()</span>
1110
+ <span class="method-click-advice">click to toggle source</span>
1111
+ </div>
1112
+
1113
+
1114
+ <div class="method-description">
1115
+
1116
+ <p>Reverses list.</p>
1117
+
1118
+
1119
+
1120
+ <div class="method-source-code" id="reverse-21-source">
1121
+ <pre>
1122
+ <span class="ruby-comment"># File ds/lists/list.rb, line 256</span>
1123
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">reverse!</span>
1124
+ <span class="ruby-ivar">@tail</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span>
1125
+ <span class="ruby-identifier">prev</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">head</span>
1126
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">next</span>
1127
+ <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">next</span> = <span class="ruby-keyword">nil</span>
1128
+ <span class="ruby-keyword">while</span> <span class="ruby-identifier">elem</span>
1129
+ <span class="ruby-identifier">nxt</span> = <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span>
1130
+ <span class="ruby-identifier">elem</span>.<span class="ruby-identifier">next</span> = <span class="ruby-identifier">prev</span>
1131
+ <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">elem</span>
1132
+ <span class="ruby-identifier">elem</span> = <span class="ruby-identifier">nxt</span>
1133
+ <span class="ruby-keyword">end</span>
1134
+
1135
+ <span class="ruby-ivar">@head</span> = <span class="ruby-identifier">prev</span>
1136
+ <span class="ruby-keyword">self</span>
1137
+
1138
+ <span class="ruby-keyword">end</span></pre>
1139
+ </div><!-- reverse-21-source -->
1140
+
1141
+ </div>
1142
+
1143
+
1144
+
1145
+
1146
+ </div><!-- reverse-21-method -->
1147
+
1148
+
1149
+ <div id="shift-method" class="method-detail ">
1150
+ <a name="method-i-shift"></a>
1151
+
1152
+
1153
+ <div class="method-heading">
1154
+ <span class="method-name">shift</span><span
1155
+ class="method-args">()</span>
1156
+ <span class="method-click-advice">click to toggle source</span>
1157
+ </div>
1158
+
1159
+
1160
+ <div class="method-description">
1161
+
1162
+ <p>Removes list head.</p>
1163
+
1164
+
1165
+
1166
+ <div class="method-source-code" id="shift-source">
1167
+ <pre>
1168
+ <span class="ruby-comment"># File ds/lists/list.rb, line 67</span>
1169
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">shift</span>
1170
+ <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">head</span>).<span class="ruby-identifier">data</span>
1171
+ <span class="ruby-keyword">end</span></pre>
1172
+ </div><!-- shift-source -->
1173
+
1174
+ </div>
1175
+
1176
+
1177
+
1178
+
1179
+ </div><!-- shift-method -->
1180
+
1181
+
1182
+ <div id="to_a-method" class="method-detail ">
1183
+ <a name="method-i-to_a"></a>
1184
+
1185
+
1186
+ <div class="method-heading">
1187
+ <span class="method-name">to_a</span><span
1188
+ class="method-args">()</span>
1189
+ <span class="method-click-advice">click to toggle source</span>
1190
+ </div>
1191
+
1192
+
1193
+ <div class="method-description">
1194
+
1195
+ <p>Converts list to array.</p>
1196
+
1197
+
1198
+
1199
+ <div class="method-source-code" id="to_a-source">
1200
+ <pre>
1201
+ <span class="ruby-comment"># File ds/lists/list.rb, line 279</span>
1202
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">to_a</span>
1203
+ <span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>}
1204
+ <span class="ruby-keyword">end</span></pre>
1205
+ </div><!-- to_a-source -->
1206
+
1207
+ </div>
1208
+
1209
+
1210
+
1211
+
1212
+ </div><!-- to_a-method -->
1213
+
1214
+
1215
+ <div id="zip-3F-method" class="method-detail ">
1216
+ <a name="method-i-zip-3F"></a>
1217
+
1218
+
1219
+ <div class="method-heading">
1220
+ <span class="method-name">zip?</span><span
1221
+ class="method-args">(other)</span>
1222
+ <span class="method-click-advice">click to toggle source</span>
1223
+ </div>
1224
+
1225
+
1226
+ <div class="method-description">
1227
+
1228
+ <p>Checks if list is linked at the end with other list.</p>
1229
+
1230
+
1231
+
1232
+ <div class="method-source-code" id="zip-3F-source">
1233
+ <pre>
1234
+ <span class="ruby-comment"># File ds/lists/list.rb, line 138</span>
1235
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">zip?</span>(<span class="ruby-identifier">other</span>)
1236
+ <span class="ruby-identifier">tail</span>.<span class="ruby-identifier">equal?</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">tail</span>
1237
+ <span class="ruby-keyword">end</span></pre>
1238
+ </div><!-- zip-3F-source -->
1239
+
1240
+ </div>
1241
+
1242
+
1243
+
1244
+
1245
+ </div><!-- zip-3F-method -->
1246
+
1247
+
1248
+ </div><!-- public-instance-method-details -->
1249
+
1250
+ </div><!-- 5Buntitled-5D -->
1251
+
1252
+
1253
+ </div><!-- documentation -->
1254
+
1255
+ <div id="validator-badges">
1256
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
1257
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
1258
+ Rdoc Generator</a> 2</small>.</p>
1259
+ </div>
1260
+
1261
+ </body>
1262
+ </html>
1263
+