This file contains 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/local/bin/ruby -w | |
# Bit masks | |
MASKA = 0XFFFF | |
MASKB = 0XFFFFFFFF | |
MASKR = 0XFFFFFFFFFFFFFFFF | |
def letter? ch; ch =~ /[a-zA-Z]/ end | |
def number? ch; ch =~ /[0-9]/ end |
This file contains 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/local/bin/ruby -w | |
# This module adds to the class that includes it the ability to flatten | |
# arbitrary nested arrays. | |
module ArrayFlattener | |
# This methods flattens an arbitrary nested array. | |
# It returns a flat array if the input is valid, nil is the input | |
# is nil, or throws an exception in any other case. | |
def flatten array, res = Array.new |
This file contains 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
def flatten array, res = Array.new | |
# 1. Does the candidate guard against invalid inputs? | |
return nil unless array | |
unless array.is_a?(Array) | |
# 2. When an error condition arises, does the candidate | |
# provides a comprehensive error message? | |
# (That is: an error message that other developer can | |
# look and immediately know what went wrong.) | |
# (*) See comments on die_arg_is_not_array for more details. | |
die_arg_is_not_array "array", array |
This file contains 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 | |
class AVLTree | |
class Node | |
attr_accessor :key, :data, :height, :left, :right | |
def initialize key, data | |
self.key = key | |
self.data = data | |
self.height = 1 |
This file contains 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
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <dirent.h> | |
#include <pwd.h> | |
#include <grp.h> | |
#include <time.h> |
This file contains 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 CircularList | |
class Node | |
attr_accessor :next, :data | |
def initialize data | |
self.data = data | |
self.next = nil | |
end | |
end | |
attr_accessor :head, :current, :length |
This file contains 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 Queue | |
class Node | |
attr_accessor :next, :data | |
def initialize data | |
self.data = data | |
self.next = nil | |
end | |
end | |
attr_accessor :head, :tail, :length |
This file contains 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_relative "./linked_list.rb" | |
class Set | |
# Set's constructor. | |
def initialize | |
@list = LinkedList.new | |
end | |
# Inserts a member into the current set. |
This file contains 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 BTree | |
attr_accessor :root, :size | |
class Node | |
attr_accessor :parent, :data, :left, :right | |
def initialize parent, data | |
self.parent = parent | |
self.data = data | |
end |
This file contains 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 AVLTree | |
# Represents an entry into the avl tree. | |
class Node | |
attr_accessor :key, :data, :height, :left, :right, :deleted | |
def initialize key, data | |
self.key = key | |
self.data = data | |
self.height = 1 |
OlderNewer