Skip to content

Instantly share code, notes, and snippets.

View andrewsouthard1's full-sized avatar

Andrew Southard andrewsouthard1

View GitHub Profile
@andrewsouthard1
andrewsouthard1 / linkedList.js
Last active July 24, 2017 14:08
Linked List
function LinkedList() {
head = null;
length = 0;
var Node = function(element) {
this.element = element;
this.next = null;
}
def quicksort(arr, first, last)
if first < last
p_index = partition(arr, first, last)
quicksort(arr, first, p_index - 1)
quicksort(arr, p_index + 1, last)
end
arr
end
@andrewsouthard1
andrewsouthard1 / quicksort.rb
Created May 20, 2017 19:39
Quicksort pseudocode
while i < last
pivot = myArray[last] — 4
myArray = [3, 4, 1, 5, 7, 1, 4]
i = 0
p_index = 0
myArray = [3, 4, 1, 5, 7, 1, 4]
arr[i] = 3 is less than or equal to 4,
3 will stay in its position(swapping 0 with 0)
i = 1
@andrewsouthard1
andrewsouthard1 / smallest_node.rb
Last active May 17, 2017 16:56
Find the smallest node in a tree
def find_smallest(node)
current = node
while current
return current.value if !current.left
current = current.left
end
end
@andrewsouthard1
andrewsouthard1 / binary_tree.rb
Created May 15, 2017 17:27
Binary Tree Class
class BinaryTreeNode
attr_accessor :value
attr_reader :left, :right
def initialize(value)
@value = value
@right = nil
@left = nil
end
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Last active June 28, 2022 20:33
Binary Search - Complete
def binary_search(n, arr)
middle = arr.length / 2
i = 0
j = arr.length - 1
while i < j
if arr[middle] == n
return true
elsif arr[middle] < n
i = middle + 1
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Last active May 10, 2017 18:22
Binary Search - After Comments
def binary_search(n, arr)
middle = arr[arr.length / 2]
i = 0
j = arr.length - 1
while i < j
if middle == n
return true
elsif middle < n
i = middle
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Created May 10, 2017 17:30
Binary Search - Before Comments
def binary_search(n, arr)
middle = arr[arr.length / 2]
i = 0
j = arr.length - 1
while i < j
if middle == n
return true
elsif middle < n
i = middle
@andrewsouthard1
andrewsouthard1 / binary_search.rb
Created May 10, 2017 17:29
Binary Search - First Draft
def binary_search(n, arr)
middle = arr[arr.length / 2]
if middle == n
return true
elsif middle < n
i = middle
j = arr.length - 1
middle = i + j / 2
else
json.array! @figures.each do |figure|
json.id figure.id
json.character figure.character
json.price figure.price
json.description figure.description
end