fastsort 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c7b13967306e965a337cf00b9b8debca59787d6ee788af65b3242e606507ae2
4
- data.tar.gz: 04a5570f6b32a7eea2f18e22e174ef53591e7968ff9b4fe1bc5222148c1f070d
3
+ metadata.gz: '08018e1e9579c8454b8cda1bfa90f63f979ffb37e948fdfc011835df2b9d1eea'
4
+ data.tar.gz: '09836fc38630639c43fa2bb7c475c34def609bb1e3d8dfeab799eb95035fedc3'
5
5
  SHA512:
6
- metadata.gz: 961c2cc4b1a10d4dbd97408546d02294ffa884a784da0655cc96a4cb74848ff50aa757c71fe3e18ec102e706bce77bd99c14e8d1d34a31af5a2180aae57ec291
7
- data.tar.gz: 17ffc5adb2895eb51c53f45512771111be4a9c4f50892fdf63d61e7ed8489b7427d12ef7386ebb46d3b104674ed1ea5894f4a0708038f688e7019b6ea742e767
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.sort_array
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
 
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fastsort
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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, 'Array cannot be nil' if array.nil?
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, 'Array cannot be empty' if array.empty?
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, 'Invalid pivot value' if pivot_value.nil?
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.3
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: 2023-12-29 00:00:00.000000000 Z
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