Ruby Source Code
- Program 2.1
- Program to compute
.
- Program 2.2
- Program to compute
using Horner's rule.
- Program 2.3
- Recursive program to compute n!.
- Program 2.4
- Linear search to find
.
- Program 2.5
- Program to compute
.
- Program 2.6
- Program to compute
.
- Program 2.7
- Program to compute
using Horner's rule.
- Program 2.8
- Program to compute
.
- Program 2.9
- Program to compute
using the closed-form expression.
- Program 3.1
- Program 2.2 again.
- Program 3.2
- Program to compute
for
.
- Program 3.3
- Non-recursive program to compute Fibonacci numbers.
- Program 3.4
- Recursive program to compute Fibonacci numbers.
- Program 3.5
- Bucket sort.
- Program 4.1
- Array class init and initialize methods.
- Program 4.2
- Array class [] and []= methods.
- Program 4.3
- Array class baseIndex accessor.
- Program 4.4
- Array class length= method.
- Program 4.5
- MultiDimensionalArray class initialize method.
- Program 4.6
- MultiDimensionalArray class [] and []= methods.
- Program 4.7
- Matrix class.
- Program 4.8
- DenseMatrix class initialize, [] and []= methods.
- Program 4.9
- DenseMatrix class times method.
- Program 4.10
- LinkedList.Element class.
- Program 4.11
- LinkedList class initialize method.
- Program 4.12
- LinkedList class purge method.
- Program 4.13
- LinkedList class properties.
- Program 4.14
- LinkedList class first and last methods.
- Program 4.15
- LinkedList class prepend method.
- Program 4.16
- LinkedList class append method.
- Program 4.17
- LinkedList class clone method.
- Program 4.18
- LinkedList class extract method.
- Program 4.19
- LinkedList.Element class insertAfter and insertBefore methods.
- Program 5.1
- AbstractObject class definition.
- Program 5.2
- Module class abstractmethod method definition.
- Program 5.3
- Container class.
- Program 5.4
- Iterator class.
- Program 5.5
- Container iter and each methods.
- Program 5.6
- Container class to_s method.
- Program 5.7
- Visitor interface.
- Program 5.8
- Container class accept method.
- Program 5.9
- SearchableContainerMethods and the SearchableContainer abstract class.
- Program 5.10
- Association class initialize method.
- Program 5.11
- Association properties.
- Program 5.12
- Association methods.
- Program 6.1
- Abstract Stack class.
- Program 6.2
- StackAsArray initialize and purge methods.
- Program 6.3
- StackAsArray class push, pop, and top methods.
- Program 6.4
- StackAsArray class each method.
- Program 6.5
- StackAsArray class iter method.
- Program 6.6
- StackAsLinkedList initialize and purge methods.
- Program 6.7
- StackAsLinkedList class push, pop and top methods.
- Program 6.8
- StackAsLinkedList class each method.
- Program 6.9
- LinkedList class each method.
- Program 6.10
- StackAsLinkedList class iter method.
- Program 6.11
- Stack application-a single-digit, RPN calculator.
- Program 6.12
- Abstract Queue class.
- Program 6.13
- QueueAsArray initialize and purge methods.
- Program 6.14
- QueueAsArray class enqueue, dequeue and head methods.
- Program 6.15
- QueueAsLinkedList class initialize and purge methods.
- Program 6.16
- QueueAsLinkedList class enqueue, dequeue and head methods.
- Program 6.17
- Queue application-breadth-first tree traversal.
- Program 6.18
- Deque module and the Deque abstract class.
- Program 6.19
- DequeAsArray class enqueueHead dequeueHead and head methods.
- Program 6.20
- DequeAsArray class enqueueTail, dequeueTail and tail methods.
- Program 6.21
- DequeAsLinkedList class enqueueHead, dequeueHead and head methods.
- Program 6.22
- DequeAsLinkedList class enqueueTail, dequeueTail and tail methods.
- Program 7.1
- Abstract OrderedList class.
- Program 7.2
- Abstract Cursor class.
- Program 7.3
- OrderedListAsArray class initialize method.
- Program 7.4
- OrderedListAsArray class insert method.
- Program 7.5
- OrderedListAsArray class member? and find methods.
- Program 7.6
- OrderedListAsArray class withdraw method.
- Program 7.7
- OrderedListAsArray::Cursor class initialize and datum methods.
- Program 7.8
- OrderedListAsArray class findPosition and and [] methods.
- Program 7.9
- OrderedListAsArray::Cursor class insertAfter method.
- Program 7.10
- OrderedListAsArray::Cursor class withdraw method.
- Program 7.11
- OrderedListAsLinkedList class initialize method.
- Program 7.12
- OrderedListAsLinkedList class insert and [] methods.
- Program 7.13
- OrderedListAsLinkedList class member? and find methods.
- Program 7.14
- OrderedListAsLinkedList class withdraw method.
- Program 7.15
- OrderedListAsLinkedList::Cursor class initialize and datum methods.
- Program 7.16
- OrderedListAsLinkedList class findPosition method
- Program 7.17
- OrderedListAsLinkedList::Cursor class insertAfter method.
- Program 7.18
- OrderedListAsLinkedList::Cursor class withdraw method.
- Program 7.19
- Polynomial::Term class.
- Program 7.20
- Abstract Polynomial class.
- Program 7.21
- PolynomialAsOrderedList class.
- Program 7.22
- Polynomial class differentiate! method.
- Program 7.23
- SortedListMethods module.
- Program 7.24
- SortedListAsArray class.
- Program 7.25
- SortedListAsArray class insert method.
- Program 7.26
- SortedListAsArray class findOffset method.
- Program 7.27
- SortedListAsArray class find and findPosition methods.
- Program 7.28
- SortedListAsArray class withdraw method.
- Program 7.29
- SortedListAsLinkedList class.
- Program 7.30
- SortedListAsLinkedList class insert method.
- Program 7.31
- Term methods.
- Program 7.32
- PolynomialAsSortedList class initialize and + methods.
- Program 8.1
- Integer class hash method.
- Program 8.2
- Float class hash method.
- Program 8.3
- String class hash method.
- Program 8.4
- Container class hash method.
- Program 8.5
- Association class hash method.
- Program 8.6
- Abstract HashTable class.
- Program 8.7
- Abstract HashTable class f, g and h methods.
- Program 8.8
- ChainedHashTable class initialize, length and purge methods.
- Program 8.9
- ChainedHashTable class insert and withdraw methods.
- Program 8.10
- ChainedHashTable class find method.
- Program 8.11
- ChainedScatterTable::Entry class initialize method.
- Program 8.12
- ChainedScatterTable class initialize, length and purge methods.
- Program 8.13
- ChainedScatterTable class insert and find methods.
- Program 8.14
- ChainedScatterTable class withdraw method.
- Program 8.15
- OpenScatterTable::Entry class initialize method.
- Program 8.16
- OpenScatterTable class initialize, length and purge methods.
- Program 8.17
- OpenScatterTable class c, findUnoccupied and insert methods.
- Program 8.18
- OpenScatterTable class findMatch and find methods.
- Program 8.19
- OpenScatterTable Class withdraw method.
- Program 8.20
- OpenScatterTableV2 class withdraw method.
- Program 8.21
- Hash/scatter table application-counting words.
- Program 9.1
- Abstract Tree class.
- Program 9.2
- Abstract Tree class depthFirstTraversal and depthFirstTraversalAccept methods.
- Program 9.3
- PrePostVisitor class.
- Program 9.4
- PreOrder class.
- Program 9.5
- InOrder class.
- Program 9.6
- PostOrder class.
- Program 9.7
- Abstract Tree class breadthFirstTraversal and breadthFirstTraversalAccept methods.
- Program 9.8
- Abstract Tree class each method.
- Program 9.9
- Abstract Tree class iter method and the Tree::Iterator class.
- Program 9.10
- GeneralTree class initialize and purge methods.
- Program 9.11
- GeneralTree class key, getSubtree, attachSubtree and detachSubtree methods.
- Program 9.12
- NaryTree class initialize and purge methods.
- Program 9.13
- NaryTree class key, empty?, attachKey and detachKey methods.
- Program 9.14
- NaryTree class getSubtree, attachSubtree and detachSubtree methods.
- Program 9.15
- BinaryTree class initialize and purge methods.
- Program 9.16
- BinaryTree left and right methods
- Program 9.17
- BinaryTree class DepthFirstTraversal method.
- Program 9.18
- BinaryTree class compareTo method.
- Program 9.19
- Binary tree application-postfix to infix conversion.
- Program 9.20
- Binary tree application-printing infix expressions.
- Program 10.1
- SearchTreeMethods module and the SearchTree abstract class.
- Program 10.2
- BinarySearchTree class initialize method.
- Program 10.3
- BinarySearchTree class find and min methods.
- Program 10.4
- BinarySearchTree class insert, attachKey and balance methods.
- Program 10.5
- BinarySearchTree class withdraw method.
- Program 10.6
- AVLTree class initialize, key, left and right methods.
- Program 10.7
- AVLTree class height, adjustHeight and balanceFactor methods.
- Program 10.8
- AVLTree class doLLRotation method.
- Program 10.9
- AVLTree class doLRRotation method.
- Program 10.10
- AVLTree class balance method.
- Program 10.11
- AVLTree class attachKey method.
- Program 10.12
- AVLTree class detachKey method.
- Program 10.13
- MWayTree class initialize and m methods.
- Program 10.14
- MWayTree class depthFirstTraversal method.
- Program 10.15
- MWayTree class find method (linear search).
- Program 10.16
- MWayTree class findIndex and find methods (binary search).
- Program 10.17
- MWayTree class insert method.
- Program 10.18
- MWayTree class withdraw method.
- Program 10.19
- BTree class initialize, attachSubtree and parent methods.
- Program 10.20
- BTree class insert method.
- Program 10.21
- BTree class insertUp method.
- Program 10.22
- Application of search trees-word translation.
- Program 11.1
- PriorityQueueMethods module and the PriorityQueue abstract class.
- Program 11.2
- MergeablePriorityQueueMethods module and the MergeablePriorityQueue abstract class.
- Program 11.3
- BinaryHeap class initialize and purge methods.
- Program 11.4
- BinaryHeap class enqueue method.
- Program 11.5
- BinaryHeap class min method.
- Program 11.6
- BinaryHeap class dequeueMin method.
- Program 11.7
- LeftistHeap class initialize, key, left, right and nullPathLength method.
- Program 11.8
- LeftistHeap class merge! method.
- Program 11.9
- LeftistHeap class enqueue method.
- Program 11.10
- LeftistHeap class min method.
- Program 11.11
- LeftistHeap class dequeueMin method.
- Program 11.12
- BinomialQueue::BinomialTree class initialize, key, list and degree methods.
- Program 11.13
- BinomialTree class add! method.
- Program 11.14
- BinomialQueue class initialize and treeList methods.
- Program 11.15
- BinomialQueue class addTree and removeTree methods.
- Program 11.16
- BinomialQueue class minTree and min methods.
- Program 11.17
- BinomialQueue class merge! method.
- Program 11.18
- BinomialQueue class fullAdder method.
- Program 11.19
- BinomialQueue class enqueue method.
- Program 11.20
- BinomialQueue class dequeueMin method.
- Program 11.21
- Simulation::Event class.
- Program 11.22
- Application of priority queues-discrete event simulation.
- Program 12.1
- Abstract Set class.
- Program 12.2
- SetAsArray class initialize and array methods.
- Program 12.3
- SetAsArray class insert, member? and withdraw methods.
- Program 12.4
- SetAsArray class |, \& and - methods.
- Program 12.5
- SetAsArray class == and <= methods.
- Program 12.6
- SetAsBitVector class initialize and vector methods.
- Program 12.7
- SetAsBitVector insert, member? and withdraw methods.
- Program 12.8
- SetAsBitVector class |, \& and - methods.
- Program 12.9
- Abstract Multiset class.
- Program 12.10
- MultisetAsArray class initialize and array methods.
- Program 12.11
- MultisetAsArray class insert, member? and withdraw methods.
- Program 12.12
- MultisetAsArray class |, \& and - methods.
- Program 12.13
- MultisetAsLinkedList class initialize and list methods.
- Program 12.14
- MultisetAsLinkedList class | method.
- Program 12.15
- MultisetAsLinkedList class \& method.
- Program 12.16
- Abstract Partition class.
- Program 12.17
- PartitionAsForest::PartitionTree class.
- Program 12.18
- PartitionAsForest class initialize method.
- Program 12.19
- PartitionAsForest class find method.
- Program 12.20
- PartitionAsForest class simple join method.
- Program 12.21
- PartitionAsForest class collapsing find method.
- Program 12.22
- PartitionAsForest class union-by-size join method.
- Program 12.23
- PartitionAsForest class union-by-rank join method.
- Program 12.24
- Application of disjoint sets-finding equivalence classes.
- Program 14.1
- Abstract Solution class.
- Program 14.2
- Abstract Solver class.
- Program 14.3
- DepthFirstSolver class init and search methods.
- Program 14.4
- BreadthFirstSolver class init and search methods.
- Program 14.5
- DepthFirstBranchAndBoundSolver class init and search methods.
- Program 14.6
- Divide-and-conquer example-binary search.
- Program 14.7
- Divide-and-conquer Example-computing Fibonacci numbers.
- Program 14.8
- Divide-and-conquer example-merge sorting.
- Program 14.9
- Dynamic programming example-computing generalized Fibonacci numbers.
- Program 14.10
- Dynamic programming example-computing Binomial coefficients.
- Program 14.11
- Dynamic programming example-typesetting a paragraph.
- Program 14.12
- RandomNumberGenerator class init, seed and next methods.
- Program 14.13
- Abstract RandomVariable class.
- Program 14.14
- SimpleRV class.
- Program 14.15
- UniformRV class.
- Program 14.16
- ExponentialRV class.
- Program 14.17
- Monte Carlo program to compute
.
- Program 15.1
- Abstract Sorter class.
- Program 15.2
- StraightInsertionSorter class initialize and doSort methods.
- Program 15.3
- BinaryInsertionSorter class initialize and doSort methods.
- Program 15.4
- BubbleSorter class initialize and doSort methods.
- Program 15.5
- Abstract QuickSorter class initialize and selectPivot methods.
- Program 15.6
- Abstract QuickSorter class quicksort method.
- Program 15.7
- Abstract QuickSorter class doSort method.
- Program 15.8
- MedianOfThreeQuickSorter class initialize and selectPivot methods.
- Program 15.9
- StraightSelectionSorter class initialize and doSort methods.
- Program 15.10
- HeapSorter class initialize and percolateDown methods.
- Program 15.11
- HeapSorter class buildHeap method.
- Program 15.12
- HeapSorter class doSort method.
- Program 15.13
- TwoWayMergeSorter initialize method.
- Program 15.14
- TwoWayMergeSorter class merge method.
- Program 15.15
- TwoWayMergeSorter class doSort and mergesort methods.
- Program 15.16
- BucketSorter class initialize method.
- Program 15.17
- BucketSorter class doSort method.
- Program 15.18
- RadixSorter class initialize method.
- Program 15.19
- RadixSorter class doSort method.
- Program 16.1
- Abstract Vertex class.
- Program 16.2
- Abstract Edge class.
- Program 16.3
- Graph::Vertex and Graph::Edge classes.
- Program 16.4
- Abstract Graph class methods.
- Program 16.5
- Abstract Graph class accessors and mutators.
- Program 16.6
- DigraphMethods module and the abstract Digraph class.
- Program 16.7
- GraphAsMatrix class initialize method.
- Program 16.8
- GraphAsLists class initialize method.
- Program 16.9
- Abstract Graph class depthFirstTraversal method.
- Program 16.10
- Abstract Graph class breadthFirstTraversal method.
- Program 16.11
- Abstract Digraph class topologicalOrderTraversal method.
- Program 16.12
- Abstract Graph class connected? method.
- Program 16.13
- Abstract Digraph class connected? method.
- Program 16.14
- Abstract Digraph class cylic? method.
- Program 16.15
- Algorithms::Entry class initialize method.
- Program 16.16
- Dijkstra's algorithm.
- Program 16.17
- Floyd's algorithm.
- Program 16.18
- Prim's algorithm.
- Program 16.19
- Kruskal's algorithm.
- Program 16.20
- Critical path analysis-finding the critical paths.
- Program A.1
- Example of parameter passing.
- Program A.2
- Complex class initialize method.
- Program A.3
- Complex class real and imag attribute accessors.
- Program A.4
- Complex class r, code{r=}, theta and theta= methods.
- Program A.5
- Complex class +, -, * and / methods.
- Program A.6
- Complex class main method.
- Program A.7
- Person class.
- Program A.8
- Parent class.
- Program A.9
- GraphicalObject class initialize, draw, erase and moveTo methods.
- Program A.10
- Point class initialize method and x and y attribute readers.
- Program A.11
- Circle class.
- Program A.12
- Rectangle class.
- Program A.13
- Square class.
- Program A.14
- Using exceptions in Ruby.
Copyright © 2004 by
Bruno R. Preiss, P.Eng. All rights reserved.