HEAP_SORT 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e0751bd2e9fb6be5ca890460cf5a0d148e3dc8c097bfe71a99901a66d9b676da
4
+ data.tar.gz: 59f2dabe3ca998f48c2711327aba6504d2dbfee78089b4529b81c386469f729b
5
+ SHA512:
6
+ metadata.gz: '008f2df7211d14a1cf0af065910b282b6ecf7c3a5cfec5358c27bfe5f682211bd35cd210b1ec3fe9b38dd366a4f28b4dfab79eb1bae41d7a28421a3fc903730c'
7
+ data.tar.gz: 0b40fd998cc43cb64fbcea5ec6edc558ba50fc27ee5a67b8e203c5365649649b07bb3faa86174c7049e6a9a7d11f858a30eb38edc046cecd4056b32e812ea80a
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # HEAPSORT
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/HEAP_SORT`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/HEAP_SORT.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HEAPSORT
4
+ VERSION = "0.1.0"
5
+ end
data/lib/HEAP_SORT.rb ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "HEAP_SORT/version"
4
+
5
+ module HEAPSORT
6
+ class Error < StandardError; end
7
+ # frozen_string_literal: true
8
+
9
+ def heapify(arr, n, i)
10
+ largest = i
11
+ left = 2 * i + 1
12
+ right = 2 * i + 2
13
+
14
+ if left < n && arr[i] < arr[left]
15
+ largest = left
16
+ end
17
+ if right < n && arr[largest] < arr[right]
18
+ largest = right
19
+ end
20
+
21
+ if largest != i
22
+ arr[i], arr[largest] = arr[largest], arr[i]
23
+ heapify(arr, n, largest)
24
+ end
25
+ end
26
+
27
+ def heap_sort(arr)
28
+ n = arr.length
29
+ (n / 2 - 1).downto(0) do |i|
30
+ heapify(arr, n, i)
31
+ end
32
+
33
+ (n - 1).downto(1) do |i|
34
+ arr[i], arr[0] = arr[0], arr[i]
35
+ heapify(arr, i, 0)
36
+ end
37
+ arr
38
+ end
39
+ end
data/sig/HEAP_SORT.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module HEAPSORT
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: HEAP_SORT
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fade
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ A Ruby implementation of the heap sort algorithm, which sorts an array by
15
+ building a max heap and then repeatedly extracting the maximum element.
16
+ email:
17
+ - dimabreusgo@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - README.md
24
+ - Rakefile
25
+ - lib/HEAP_SORT.rb
26
+ - lib/HEAP_SORT/version.rb
27
+ - sig/HEAP_SORT.rbs
28
+ homepage: https://github.com/sgn-fade/HEAP_SORT
29
+ licenses: []
30
+ metadata:
31
+ allowed_push_host: https://rubygems.org
32
+ homepage_uri: https://github.com/sgn-fade/HEAP_SORT
33
+ source_code_uri: https://github.com/sgn-fade/HEAP_SORT
34
+ changelog_uri: https://github.com/sgn-fade/HEAP_SORT
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.16
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Heap Sort Algorithm
54
+ test_files: []