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
function LinkedList() { | |
head = null; | |
length = 0; | |
var Node = function(element) { | |
this.element = element; | |
this.next = null; | |
} |
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
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 |
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
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 |
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
def find_smallest(node) | |
current = node | |
while current | |
return current.value if !current.left | |
current = current.left | |
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
class BinaryTreeNode | |
attr_accessor :value | |
attr_reader :left, :right | |
def initialize(value) | |
@value = value | |
@right = nil | |
@left = nil | |
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
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 |
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
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 |
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
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 |
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
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 |
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
json.array! @figures.each do |figure| | |
json.id figure.id | |
json.character figure.character | |
json.price figure.price | |
json.description figure.description | |
end |
NewerOlder