pavsort 0.0.1 → 0.0.2
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/lib/pavsort.rb +4 -75
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80ef292d2c175ab8f16116b521e22017370b704
|
4
|
+
data.tar.gz: 14b466fb6137007ddfc06f65af728822a2edb443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d588187fd2cd64ee26351c008172ef12e0c3ca0c038af2fc549cbe7049483eeef6ff5e02f0ff9daf1194e22162dfec6a95b93e9c1b9262c02f282b9ba89df91
|
7
|
+
data.tar.gz: b34af2b49378f004764f63b58b264b60428493eecae5fffa1213ab4c1c7467c5c6d2916121ba2f7ab5046ac0a577adf80e569f139f00fc6774c9ed7059e993ee
|
data/lib/pavsort.rb
CHANGED
@@ -1,82 +1,11 @@
|
|
1
1
|
module Pavsort
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
private
|
4
4
|
|
5
|
-
|
5
|
+
class SuperSort
|
6
|
+
def self.sort(array)
|
6
7
|
part = array.partition{|element| element.respond_to?(:/)}
|
7
8
|
num_sort(part.first) + alph_sort(part.last)
|
8
9
|
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def alph_sort(array)
|
13
|
-
return array if array.length <= 1
|
14
|
-
first_half, second_half = split_array_in_half(array)
|
15
|
-
return alph_merge(alph_sort(first_half),alph_sort(second_half))
|
16
|
-
end
|
17
|
-
|
18
|
-
def num_sort(array)
|
19
|
-
return array if array.length <= 1
|
20
|
-
first_half, second_half = split_array_in_half(array)
|
21
|
-
return num_merge(num_sort(first_half),num_sort(second_half))
|
22
|
-
end
|
23
|
-
|
24
|
-
def split_array_in_half(array)
|
25
|
-
mid_index = array.length / 2
|
26
|
-
[array.take(mid_index), array.drop(mid_index)]
|
27
|
-
end
|
28
|
-
|
29
|
-
def alph_merge(left, right)
|
30
|
-
result = []
|
31
|
-
until left.empty? && right.empty?
|
32
|
-
case
|
33
|
-
when left.empty? then result << right.shift
|
34
|
-
when right.empty? then result << left.shift
|
35
|
-
when left.first.downcase < right.first.downcase then result << left.shift
|
36
|
-
when right.first.downcase < left.first.downcase then result << right.shift
|
37
|
-
end
|
38
|
-
end
|
39
|
-
result
|
40
|
-
end
|
41
|
-
|
42
|
-
def num_merge(left, right)
|
43
|
-
result = []
|
44
|
-
until left.empty? && right.empty?
|
45
|
-
case
|
46
|
-
when left.empty? then result << right.shift
|
47
|
-
when right.empty? then result << left.shift
|
48
|
-
when left.first < right.first then result << left.shift
|
49
|
-
when right.first < left.first then result << right.shift
|
50
|
-
end
|
51
|
-
end
|
52
|
-
result
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class Quick
|
58
|
-
class << self
|
59
|
-
|
60
|
-
def sort(array)
|
61
|
-
part = array.partition{|element| element.respond_to?(:/)}
|
62
|
-
num_sort(part.first) + alph_sort(part.last)
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def num_sort(array)
|
68
|
-
return array if array.length <= 1
|
69
|
-
pivot = array.delete_at(rand(array.length))
|
70
|
-
partition = array.partition{|element| element < pivot}
|
71
|
-
num_sort(partition.first) + [pivot] + num_sort(partition.last)
|
72
|
-
end
|
73
|
-
|
74
|
-
def alph_sort(array)
|
75
|
-
return array if array.length <= 1
|
76
|
-
pivot = array.delete_at(rand(array.length))
|
77
|
-
partition = array.partition{|element| element.downcase < pivot.downcase}
|
78
|
-
alph_sort(partition.first) + [pivot] + alph_sort(partition.last)
|
79
|
-
end
|
80
10
|
end
|
81
|
-
end
|
82
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pavsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Vargas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Merge sort and Quick sort methods implemented in ruby. Methods are case
|
14
14
|
and numerically insensitive
|