Skip to content

Instantly share code, notes, and snippets.

View seanreed1111's full-sized avatar

Sean Reed seanreed1111

View GitHub Profile
@seanreed1111
seanreed1111 / Breadth_First_Search.rb
Last active December 31, 2015 14:18
Breadth First Search
require '../lib/Queue'
frontier = Queue.new
# set up the adjacency list that defines the graph
neighbors = {}
neighbors = {:a => [:b,:f], :b => [:c,:d], :c => [:e], :d =>[:e], :e =>[:c,:d],
:f => [:a,:g,:h,:i], :g => [:f], :h => [:f], :i => [:f] }
parent = {}
@seanreed1111
seanreed1111 / SimpleQueue.rb
Last active December 29, 2015 13:49
implementation of class SimpleQueue
class SimpleQueue
def initialize
@queue = Array.new
end
#adds item to back of queue and returns the queue
def enqueue(item)
@queue.unshift(item)
end
@seanreed1111
seanreed1111 / SimpleStack.rb
Last active December 29, 2015 13:39
class SimpleStack
class SimpleStack
def initialize
@stack = Array.new
end
#removes the first item from the stack and returns the item popped
def pop
@stack.pop
end
@seanreed1111
seanreed1111 / fizzbuzz_gist
Created November 19, 2013 20:28
FizzBuzz method
def fizzbuzz(number)
if number % 15 == 0
"Fizzbuzz"
elsif number % 3 == 0
"Fizz"
elsif number % 5 == 0
"Buzz"
else
number
end