kimquy_algo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -12
- data/kimquy_algo.gemspec +1 -1
- data/lib/kimquy_algo/version.rb +1 -1
- data/lib/kimquy_algo.rb +27 -8
- data/pkg/kimquy_algo-0.0.1.gem +0 -0
- metadata +3 -3
- data/.gitignore +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02d99f4a0be8d7c4109261332c9165392600a890
|
4
|
+
data.tar.gz: a9ce587853849046b45b87f3d02683403d51a8f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e3623ac9b32f7ff3c4cea76852668b27805c18cc446a658445cce0a96546dfe4554da52704b1eeaaa16e3924cd2c1566eb2d1ad51b18a55e5fffd400c6001ec
|
7
|
+
data.tar.gz: dc5cd3de277d4b63028447f05e49eb82b97193a157aa4c9c8678d95362a5881391208602972cdafbd871e1b20d627776ffa60cf4d5c191d1cddef527f1b4cdf9
|
data/README.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# KimquyAlgo
|
2
2
|
|
3
|
-
|
3
|
+
I created a simple ruby gem for sorting algorithms:
|
4
|
+
+ insertion sort
|
5
|
+
+ merge sort
|
6
|
+
+ quick sort
|
7
|
+
|
8
|
+
updating...
|
9
|
+
|
10
|
+
example: <br/>
|
11
|
+
array = [10,9,8,7,6,5,4,3,2,1] <br/>
|
12
|
+
array.quicksort -> [1,2,3,4,5,6,7,8,9,10] <br/>
|
4
13
|
|
5
14
|
## Installation
|
6
15
|
|
@@ -16,14 +25,3 @@ Or install it yourself as:
|
|
16
25
|
|
17
26
|
$ gem install kimquy_algo
|
18
27
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/kimquy_algo.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["nguy1461@vandals.uidaho.edu"]
|
11
11
|
spec.description = %q{Algorithm and data structure}
|
12
12
|
spec.summary = %q{Algorithm library}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/kimquy/kimquy_algo"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/kimquy_algo/version.rb
CHANGED
data/lib/kimquy_algo.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module KimquyAlgo
|
4
|
-
# Your code goes here...
|
1
|
+
module Sorting
|
5
2
|
def kimquy_quicksort(a, p, r)
|
6
3
|
if p < r
|
7
4
|
q = partition(a, p, r)
|
@@ -42,14 +39,31 @@ module KimquyAlgo
|
|
42
39
|
end
|
43
40
|
end
|
44
41
|
|
45
|
-
def merge
|
46
|
-
|
47
|
-
|
42
|
+
def merge(a, p, q, r)
|
43
|
+
|
44
|
+
left = a[p..q-1]
|
45
|
+
right = a[q..r]
|
46
|
+
|
47
|
+
left << 1000000000 #sentinel
|
48
|
+
right << 1000000000 #sentinel
|
48
49
|
|
50
|
+
i = 0
|
51
|
+
j = 0
|
52
|
+
k = p
|
53
|
+
k.upto(r-1) do |x|
|
54
|
+
if left[i] <= right[j]
|
55
|
+
a[x] = left[i]
|
56
|
+
i = i + 1
|
57
|
+
else
|
58
|
+
a[x] = right[j]
|
59
|
+
j = j + 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
49
63
|
end
|
50
64
|
|
51
65
|
class Array
|
52
|
-
include
|
66
|
+
include Sorting
|
53
67
|
|
54
68
|
define_method(:swap) do |i,j|
|
55
69
|
temp = self[i]
|
@@ -72,4 +86,9 @@ class Array
|
|
72
86
|
self[i+1] = key
|
73
87
|
end
|
74
88
|
end
|
89
|
+
|
90
|
+
define_method(:merge_sort) do
|
91
|
+
kimquy_merge_sort(self,0,self.length)
|
92
|
+
end
|
75
93
|
end
|
94
|
+
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kimquy_algo
|
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
|
- long nguyen
|
@@ -45,7 +45,6 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
48
|
- Gemfile
|
50
49
|
- LICENSE.txt
|
51
50
|
- README.md
|
@@ -53,7 +52,8 @@ files:
|
|
53
52
|
- kimquy_algo.gemspec
|
54
53
|
- lib/kimquy_algo.rb
|
55
54
|
- lib/kimquy_algo/version.rb
|
56
|
-
|
55
|
+
- pkg/kimquy_algo-0.0.1.gem
|
56
|
+
homepage: https://github.com/kimquy/kimquy_algo
|
57
57
|
licenses:
|
58
58
|
- MIT
|
59
59
|
metadata: {}
|