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 <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
typedef struct person { | |
char *name; | |
struct person *next; | |
} person; | |
void display(person *start) { |
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
#Example | |
# Input: {"first1"=>"hi", "first2"=>{"second"=>"gah", "second1"=>{"third1"=>"toot"}, "second2"=>"gah3"}} | |
# Output: {:first1=>"hi", :first2=>{:second=>"gah", :second1=>{:third1=>"toot"}, :second2=>"gah3"}} | |
def symbolize(hash) | |
temp_hash = {} | |
hash.map do |k,v| | |
temp_hash[k.to_sym] = v | |
if v.is_a?(Hash) | |
temp_hash[k.to_sym] = symbolize(v) |
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
#Example | |
# Input: {"first1"=>"hi", "first2"=>{"second"=>"gah", "second1"=>{"third1"=>"toot"}, "second2"=>"gah3"}} | |
# Output: {:first1=>"hi", :first2=>{:second=>"gah", :second1=>{:third1=>"toot"}, :second2=>"gah3"}} | |
def symbolize(hash) | |
toprocess = [hash] | |
while h = toprocess.shift | |
h.keys.each do |k| | |
v = h[k] | |
if v.is_a?(Hash) |
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 insertion_sort(array) | |
for j in 1...array.length | |
i = j - 1 | |
key = array[j] | |
while i >= 0 && array[i] > key | |
array[i+1] = array[i] | |
i = i - 1 | |
end | |
array[i+1] = key | |
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 Node | |
attr_accessor :key, :value, :left, :right, :size | |
def initialize(key, value) | |
@key = key | |
@value = value | |
@size = 0 | |
@left, @right = nil, nil | |
end | |
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 Stack | |
def initialize(size=10) | |
raise "InvalidSizeInput" unless size.is_a?(Fixnum) | |
@store = Array.new(size) | |
@size = size | |
@top = 0 | |
end | |
def push(ele) |
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 | |
def initialize(size=10) | |
raise 'InvalidInputType' unless size.is_a?(Fixnum) | |
@store = Array.new(size) | |
@size = size | |
@tail = @head = 0 | |
end | |
def enqueue(ele) |
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 Node | |
attr_accessor :left, :right, :parent, :key | |
def initialize(key) | |
@parent = @left = @right = nil | |
@key = key | |
end | |
end | |
class BST |
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 MaxHeap | |
def self.heapify(arr, i) | |
l = left(i) | |
r = right(i) | |
heap_size = arr.size - 1 | |
if l <= heap_size && arr[l] > arr[i] |
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/python | |
# This was written to help with common sentinel misconfigurations. | |
# This script will loop through each of your sentinels nodes and properly reconfigure them to monitor the master node. | |
# Instructions | |
# 1. Modify the instance variable values to reflect your setup. | |
# 2. Run the script. | |
import sys |
OlderNewer