fastsort 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fastsort-0.1.4.gem +0 -0
- data/lib/fastsort/version.rb +1 -1
- data/lib/fastsort.rb +35 -6
- data/main.rb +7 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc6da324d5e82ea3fc7e86f3c1867c4bfb71fffde7f40c61adc91993bf814793
|
4
|
+
data.tar.gz: f029598b6363d8d10f6b0b561cf03d3570d4e7d8d69dcf340802dda72b89a2a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1277ee60c4cfed9ef92694f114fa8384546d45f6cfafaac3ea736a1d8d36fd9782228f969257c70a80c9d7a56afbb4442b540e12d653f2d992f2ada6f9f76487
|
7
|
+
data.tar.gz: 690a0f5c5668af181d8fd469fdc7c6a89810e7ee9c4161b9f5fba32537a5a6bcdd2e0f774fe94b6731fe5b658fd2a3e7b8d847a8b3c63bd44cf55d37a94d0a0e
|
data/fastsort-0.1.4.gem
ADDED
Binary file
|
data/lib/fastsort/version.rb
CHANGED
data/lib/fastsort.rb
CHANGED
@@ -171,17 +171,16 @@ module Fastsort
|
|
171
171
|
|
172
172
|
def sort_array
|
173
173
|
raise ArgumentError, "Array cannot be empty" if array.empty?
|
174
|
+
selection_sort(array)
|
174
175
|
end
|
175
176
|
|
176
177
|
def selection_sort(arr)
|
177
|
-
|
178
|
+
arr.each_index do |i|
|
178
179
|
min_idx = i
|
179
|
-
|
180
|
-
if arr[j] < arr[min_idx]
|
181
|
-
min_idx = j
|
182
|
-
end
|
180
|
+
(i..arr.length - 1).each do |j|
|
181
|
+
min_idx = j if arr[j] < arr[min_idx]
|
183
182
|
end
|
184
|
-
swap_values(
|
183
|
+
swap_values(i, min_idx)
|
185
184
|
end
|
186
185
|
end
|
187
186
|
|
@@ -189,4 +188,34 @@ module Fastsort
|
|
189
188
|
array[let_idx_a], array[let_idx_b] = array[let_idx_b], array[let_idx_a]
|
190
189
|
end
|
191
190
|
end
|
191
|
+
|
192
|
+
class BubbleSort
|
193
|
+
attr_accessor :array
|
194
|
+
|
195
|
+
def initialize(array)
|
196
|
+
raise ArgumentError, "Array cannot be nil" if array.nil?
|
197
|
+
@array = array
|
198
|
+
end
|
199
|
+
|
200
|
+
def sort_array
|
201
|
+
raise ArgumentError, "Array cannot be empty" if array.empty?
|
202
|
+
bubble_sort(array)
|
203
|
+
end
|
204
|
+
|
205
|
+
def bubble_sort(arr)
|
206
|
+
n = arr.length
|
207
|
+
loop do
|
208
|
+
swapped = false
|
209
|
+
|
210
|
+
(n - 1).times do |i|
|
211
|
+
if arr[i] > arr[i + 1]
|
212
|
+
arr[i], arr[i + 1] = arr[i + 1], arr[i]
|
213
|
+
swapped = true
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
break unless swapped
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
192
221
|
end
|
data/main.rb
CHANGED
@@ -39,13 +39,16 @@ sorter_001 = Fastsort::Quicksort.new(arr)
|
|
39
39
|
sorter_002 = Fastsort::Mergesort.new(arr)
|
40
40
|
sorter_003 = Fastsort::Sonicsort.new(arr)
|
41
41
|
sorter_004 = Fastsort::SelectionSort.new(arr)
|
42
|
+
sorter_005 = Fastsort::BubbleSort.new(arr)
|
42
43
|
|
43
44
|
sorter_001.sort_array
|
44
45
|
sorter_002.sort_array
|
45
46
|
sorter_003.sort_quick_and_merge
|
46
47
|
sorter_004.sort_array
|
48
|
+
sorter_005.sort_array
|
47
49
|
|
48
|
-
puts "Sorted Array Quicksort: #{sorter_001.array}"
|
49
|
-
puts "Sorted Array Mergesort: #{sorter_002.array}"
|
50
|
-
puts "Sorted Array Sonicsort: #{sorter_003.array}"
|
51
|
-
puts "Sorted Array SelectionSort: #{sorter_004.array}"
|
50
|
+
# puts "Sorted Array Quicksort: #{sorter_001.array}"
|
51
|
+
# puts "Sorted Array Mergesort: #{sorter_002.array}"
|
52
|
+
# puts "Sorted Array Sonicsort: #{sorter_003.array}"
|
53
|
+
# puts "Sorted Array SelectionSort: #{sorter_004.array}"
|
54
|
+
puts "Sorted Array SelectionSort: #{sorter_005.array}"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dants0
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- fastsort-0.1.1.gem
|
26
26
|
- fastsort-0.1.2.gem
|
27
27
|
- fastsort-0.1.3.gem
|
28
|
+
- fastsort-0.1.4.gem
|
28
29
|
- fastsort.gemspec
|
29
30
|
- lib/fastsort.rb
|
30
31
|
- lib/fastsort/version.rb
|