fastsort 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/fastsort-0.1.3.gem +0 -0
- data/lib/fastsort/version.rb +1 -1
- data/lib/fastsort.rb +31 -4
- data/main.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08018e1e9579c8454b8cda1bfa90f63f979ffb37e948fdfc011835df2b9d1eea'
|
4
|
+
data.tar.gz: '09836fc38630639c43fa2bb7c475c34def609bb1e3d8dfeab799eb95035fedc3'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e5d81f92f004e9add3cc6d4e14ee6e15d832a8fc5977b610304c82a4c3de3577e5540467d30328a71ed34b153bc8f2d8467578bbcff3999e4ef6787720e9f19
|
7
|
+
data.tar.gz: 2f35f038b12503ab1a4e415cabb44e0f886601ef85877010ddc3863b1f62f3c73017b3c89e2c06d876a61312a09c69d6c59d8bae7c78a326b7891ba651ad7471
|
data/README.md
CHANGED
@@ -31,14 +31,17 @@ arr = [
|
|
31
31
|
sorter001 = Fastsort::Quicksort.new(arr)
|
32
32
|
sorter002 = Fastsort::Mergesort.new(arr)
|
33
33
|
sorter003 = Fastsort::Sonicsort.new(arr)
|
34
|
+
sorter004 = Fastsort::SelectionSort.new(arr)
|
34
35
|
|
35
36
|
sorter001.sort_array
|
36
37
|
sorter002.sort_array
|
37
|
-
sorter003.
|
38
|
+
sorter003.sort_quick_and_merge
|
39
|
+
sorter004.sort_array
|
38
40
|
|
39
41
|
puts "Sorted Array: #{sorter001.array}"
|
40
42
|
puts "Sorted Array: #{sorter002.array}"
|
41
43
|
puts "Sorted Array: #{sorter003.array}"
|
44
|
+
puts "Sorted Array: #{sorter004.array}"
|
42
45
|
|
43
46
|
|
44
47
|
|
data/fastsort-0.1.3.gem
ADDED
Binary file
|
data/lib/fastsort/version.rb
CHANGED
data/lib/fastsort.rb
CHANGED
@@ -86,12 +86,12 @@ module Fastsort
|
|
86
86
|
attr_accessor :array
|
87
87
|
|
88
88
|
def initialize(array)
|
89
|
-
raise ArgumentError,
|
89
|
+
raise ArgumentError, "Array cannot be nil" if array.nil?
|
90
90
|
@array = array
|
91
91
|
end
|
92
92
|
|
93
93
|
def sort_quick_and_merge
|
94
|
-
raise ArgumentError,
|
94
|
+
raise ArgumentError, "Array cannot be empty" if array.empty?
|
95
95
|
quicksort(0, array.length - 1)
|
96
96
|
merge_sort(0, array.length - 1)
|
97
97
|
self
|
@@ -112,7 +112,7 @@ module Fastsort
|
|
112
112
|
pivot_idx = to_idx
|
113
113
|
pivot_value = array[pivot_idx]
|
114
114
|
|
115
|
-
raise ArgumentError,
|
115
|
+
raise ArgumentError, "Invalid pivot value" if pivot_value.nil?
|
116
116
|
|
117
117
|
pointer_b_idx = from_idx
|
118
118
|
|
@@ -131,7 +131,6 @@ module Fastsort
|
|
131
131
|
pointer_b_idx
|
132
132
|
end
|
133
133
|
|
134
|
-
|
135
134
|
def merge_sort(from_idx, to_idx)
|
136
135
|
return if from_idx >= to_idx
|
137
136
|
|
@@ -162,4 +161,32 @@ module Fastsort
|
|
162
161
|
end
|
163
162
|
end
|
164
163
|
|
164
|
+
class SelectionSort
|
165
|
+
attr_accessor :array
|
166
|
+
|
167
|
+
def initialize(array)
|
168
|
+
raise ArgumentError, "Array cannot be nil" if array.nil?
|
169
|
+
@array = array
|
170
|
+
end
|
171
|
+
|
172
|
+
def sort_array
|
173
|
+
raise ArgumentError, "Array cannot be empty" if array.empty?
|
174
|
+
end
|
175
|
+
|
176
|
+
def selection_sort(arr)
|
177
|
+
for i in arr.length
|
178
|
+
min_idx = i
|
179
|
+
for j in i..arr.length - 1
|
180
|
+
if arr[j] < arr[min_idx]
|
181
|
+
min_idx = j
|
182
|
+
end
|
183
|
+
end
|
184
|
+
swap_values(arr[i], arr[min_i])
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def swap_values(let_idx_a, let_idx_b)
|
189
|
+
array[let_idx_a], array[let_idx_b] = array[let_idx_b], array[let_idx_a]
|
190
|
+
end
|
191
|
+
end
|
165
192
|
end
|
data/main.rb
CHANGED
@@ -32,16 +32,20 @@ arr = [
|
|
32
32
|
280, 488, 411, 363, 436, 41, 356, 399, 304, 229, 254, 430, 259, 203, 201,
|
33
33
|
115, 350, 370, 124, 382, 421, 498, 139, 345, 438, 69, 431, 27, 317, 215,
|
34
34
|
47, 67, 251, 272, 144, 333, 220, 168, 465, 328, 130, 170, 294, 167, 52,
|
35
|
-
409, 117, 487, 138, 461, 489
|
35
|
+
409, 117, 487, 138, 461, 489,
|
36
|
+
]
|
36
37
|
|
37
38
|
sorter_001 = Fastsort::Quicksort.new(arr)
|
38
39
|
sorter_002 = Fastsort::Mergesort.new(arr)
|
39
40
|
sorter_003 = Fastsort::Sonicsort.new(arr)
|
41
|
+
sorter_004 = Fastsort::SelectionSort.new(arr)
|
40
42
|
|
41
43
|
sorter_001.sort_array
|
42
44
|
sorter_002.sort_array
|
43
45
|
sorter_003.sort_quick_and_merge
|
46
|
+
sorter_004.sort_array
|
44
47
|
|
45
48
|
puts "Sorted Array Quicksort: #{sorter_001.array}"
|
46
49
|
puts "Sorted Array Mergesort: #{sorter_002.array}"
|
47
50
|
puts "Sorted Array Sonicsort: #{sorter_003.array}"
|
51
|
+
puts "Sorted Array SelectionSort: #{sorter_004.array}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dants0
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Designed to efficiently organize the elements of an array in a specific
|
14
14
|
order. Sorting is a fundamental operation in computer science and data processing,
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- fastsort-0.1.0.gem
|
25
25
|
- fastsort-0.1.1.gem
|
26
26
|
- fastsort-0.1.2.gem
|
27
|
+
- fastsort-0.1.3.gem
|
27
28
|
- fastsort.gemspec
|
28
29
|
- lib/fastsort.rb
|
29
30
|
- lib/fastsort/version.rb
|