Skip to content

ameowlia/compare-sort

Repository files navigation

#compare-sort compare-sort is a gem that allows users to select a specific sorting algorithm to use, time a specific algorithm, or compare the times of all sorting algorithms.

See the gem homepage here.

##Setup

In the terminal run

gem install compare-sort

Add the following to the top of your Ruby file

require 'compare-sort'

##Usage

###Valid Data For Sorting

Your data must be in an array. All elements must be strings OR numbers.

valid_data1 = [1, 2, 3.5, 0]
valid_data2 = ["r", "u", "b", "y"]

###Sort Using a Specific Algorithm

numbers = [1, 2, 3.5, 0]

# The data needs to be passed in as a hash
# The sorting method needs to be specified as a string
CompareSort.run(data: numbers, sorting_method: "BubbleSort")
# => [0, 1, 2, 3.5]

# The valid sorting method names are: 
# - BubbleSort (0.0.1+)
# - ModifiedBubbleSort (0.0.1+)
# - SelectionSort (0.0.1+)
# - InsertionSort (0.0.1+)
# - QuickSort (0.1.0+)
# - MergeSort (0.1.0+)
# - HeapSort (0.1.1+)

###Time Specific Algorithm

numbers = [1, 2, 3.5, 0]

# Timer boolean needs to be passed in as a hash
CompareSort.run(data: numbers, sorting_method: "BubbleSort", timer: true)
# => 2.2e-05

###Compare Times of All Algorithms Use gem 0.1.0+ for comparing all algorithms.

numbers = [1, 2, 3.5, 0]

# Without a terminal output 
CompareSort.compare_all(data: numbers)
# => {"SelectionSort"=>2.2e-05, "BubbleSort"=>1.9e-05, "ModifiedBubbleSort"=>2.5e-05, "InsertionSort"=>1.9e-05} 

# With a terminal output 
CompareSort.compare_all(data: numbers, view: true)
# => {"SelectionSort"=>2.2e-05, "BubbleSort"=>1.9e-05, "ModifiedBubbleSort"=>2.5e-05, "InsertionSort"=>1.9e-05} 

compare all

About

A gem that will allow users to choose a sorting algorithm to use or compare the time each sorting alg takes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages