This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
module Search | |
extend self | |
def binary(container, item) | |
_binary container, item, 0, container.length | |
end | |
def _binary(container, item, min, max) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
module Tree | |
class Node | |
include Comparable | |
include Enumerable | |
attr_accessor :parent, :children, :element | |
def initialize(element) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Heap | |
Node = Struct.new :key, :value do | |
include Comparable | |
def <=> (other) | |
self.key <=> other.key | |
end | |
end | |
def initialize(items = []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
class Heap | |
Node = Struct.new :key, :value do | |
include Comparable | |
def <=> (other) | |
self.key <=> other.key | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
class PriorityQueue | |
include Enumerable | |
Node = Struct.new :priority, :element, :prev, :next | |
attr_reader :head, :tail, :size | |
def initialize(items = []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
class Queue | |
include Enumerable | |
Node = Struct.new :element, :next | |
attr_reader :head, :tail, :size | |
def initialize(items = []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
# LIFO | |
class Stack | |
include Enumerable | |
Node = Struct.new :element, :next | |
attr_reader :head, :size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# anagram_palindrome.rb | |
module AnagramPalindrome | |
ASCII_COUNT = 256 | |
def anagram_of_palindrome? | |
empty? | |
histogram = Array.new ASCII_COUNT, 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# anagram.rb | |
module Anagram | |
ASCII_COUNT = 256 | |
def sort | |
self.chars.sort.join | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# http.rb | |
# | |
# Sample application showing how to create HTTP request using TCP Sockets in Ruby | |
require 'socket' | |
class Request | |
attr_reader :method, :host, :resource, :client, :lines |