SnowArraySort 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,38 +2,37 @@ module SnowArraySort
2
2
  class MASort
3
3
  include SnowArraySort
4
4
 
5
- def mergesort(array)
6
- def merge(left_sorted, right_sorted)
7
- res = []
8
- l = 0
9
- r = 0
5
+ def mergesort(array)
6
+ def merge(left_sorted, right_sorted)
7
+ res = []
8
+ l = 0
9
+ r = 0
10
10
 
11
- loop do
12
- break if r >= right_sorted.length and l >= left_sorted.length
11
+ loop do
12
+ break if r >= right_sorted.length and l >= left_sorted.length
13
13
 
14
- if r >= right_sorted.length or (l < left_sorted.length and left_sorted[l] < right_sorted[r])
15
- res << left_sorted[l]
16
- l += 1
17
- else
18
- res << right_sorted[r]
19
- r += 1
20
- end
14
+ if r >= right_sorted.length or (l < left_sorted.length and left_sorted[l] < right_sorted[r])
15
+ res << left_sorted[l]
16
+ l += 1
17
+ else
18
+ res << right_sorted[r]
19
+ r += 1
21
20
  end
22
-
23
- return res
24
21
  end
25
22
 
26
- def mergesort_iter(array_sliced)
27
- return array_sliced if array_sliced.length <= 1
28
-
29
- mid = array_sliced.length/2 - 1
30
- left_sorted = mergesort_iter(array_sliced[0..mid])
31
- right_sorted = mergesort_iter(array_sliced[mid+1..-1])
32
- return merge(left_sorted, right_sorted)
33
- end
23
+ return res
24
+ end
25
+
26
+ def mergesort_iter(array_sliced)
27
+ return array_sliced if array_sliced.length <= 1
34
28
 
35
- mergesort_iter(array)
29
+ mid = array_sliced.length/2 - 1
30
+ left_sorted = mergesort_iter(array_sliced[0..mid])
31
+ right_sorted = mergesort_iter(array_sliced[mid+1..-1])
32
+ return merge(left_sorted, right_sorted)
36
33
  end
34
+
35
+ mergesort_iter(array)
37
36
  end
38
37
  end
39
38
  end
@@ -1,4 +1,4 @@
1
1
  module SnowArraySort
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SnowArraySort
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: