Skip to content

Instantly share code, notes, and snippets.

View bluetwin's full-sized avatar

Brandon Sislow bluetwin

View GitHub Profile
@bluetwin
bluetwin / dijkstra.rb
Last active December 10, 2015 19:28 — forked from yaraki/dijkstra.rb
Updated Graph with dijkstra's algorithm. Refactored from AdjacentList to Matrix. Used pqueue(https://github.com/rubyworks/pqueue) for shortest distance
#!/usr/bin/ruby
require 'pqueue'
class Graph
attr_reader :edges
INFINITY = 1 << 32
def initialize(size)
@edges = Array.new(size) {Array.new(size)}
end
@bluetwin
bluetwin / BinaryTree.rb
Last active December 10, 2015 18:08 — forked from anonymous/BinaryTree.rb
Basic BinaryTree class
#!/usr/bin/ruby
class BinaryTree
include Enumerable
attr_accessor :key, :data, :left, :right
def initialize(h) # assume h is form {:key => k, :data=>d}
@key = @data = nil
assign_key_data(h)
@left = @right = nil