Description and usage:
require ''
.new
Install the rspec gem
gem install rspec
Run the spec
rspec _spec.rb
| Gem::Specification.new do |s| | |
| s.name = '' | |
| s.summary = '' | |
| s.description = '' | |
| s.version = '0.0.1' | |
| s.platform = Gem::Platform::RUBY | |
| s.files = ['.rb'] | |
| s.require_path = '.' | |
| s.author = '' | |
| s.email = '' | |
| s.homepage = '' | |
| s.test_file = '_spec.rb' | |
| s.add_development_dependency('rspec', ["~> 2.8"]) | |
| end | |
| class PriorityQueue | |
| def initialize() @store = {} end | |
| # Takes element and it's priority. | |
| # Returns an array of elements with the same priority. | |
| def enq(el, p) | |
| @store[p] ? @store[p].push(el) : @store[p] = [el] | |
| return @store[p] | |
| end | |
| # Returns the element/priority combination of the | |
| # element with the highest priority from the queue | |
| def deq | |
| key = @store.keys.sort.last | |
| el = @store[key].shift | |
| @store.delete(key) if @store[key].empty? | |
| return [el, key] | |
| rescue NoMethodError | |
| nil | |
| end | |
| end |
| require File.expand_path('') | |
| describe do | |
| it 'should have tests' do | |
| pending | |
| end | |
| end |