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(value) { | |
this.head = null; | |
this.length = 0; | |
this.addToHead(value); | |
} | |
LinkedList.prototype.addToHead = function(value) { | |
var newNode = { value: value } ; | |
newNode.next = this.head; | |
this.head = newNode; |
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 Queue() { | |
this.dataStore = []; | |
this.enqueue = enqueue; | |
this.dequeue = dequeue; | |
this.front = front; | |
this.back = back; | |
this.toString = toString; | |
this.empty = empty; | |
} |
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 Stack() { | |
this.dataStore = []; | |
this.top = 0; | |
this.push = push; | |
this.pop = pop; | |
this.peek = peek; | |
this.clear = clear; | |
this.length = length; | |
} |
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
var EventBusClass = {}; | |
EventBusClass = function() { | |
this.listeners = {}; | |
}; | |
EventBusClass.prototype = { | |
addEventListener: function(type, callback, scope) { | |
var args = []; | |
var numOfArgs = arguments.length; | |
for(var i=0; i<numOfArgs; i++){ | |
args.push(arguments[i]); |
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
var Node = function (name) { | |
this.children = []; | |
this.name = name; | |
} | |
Node.prototype = { | |
add: function (child) { | |
this.children.push(child); | |
}, | |
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
== requires jquery ==== | |
==== html ====== | |
<div id="show"></div> | |
===== js ====== | |
function switchcase(cases,defaultCase,key) { | |
if (cases.hasOwnProperty(key)) { | |
return cases[key]; | |
} 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
<?php | |
// Creating a JS 'like' Object in PHP | |
class JSObject { | |
function __construct($members = array()) { | |
foreach ($members as $name => $value) { | |
$this->$name = $value; | |
} | |
} | |
function __call($name, $args) { |
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
<?php | |
$unsorted = array(43,21,2,1,9,24,2,99,23,8,7,114,92,5); | |
function quick_sort($array) | |
{ | |
// find array size | |
$length = count($array); | |
// base case test, if array of length 0 then just return array to caller |
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
//HashTable | |
function HashTable() { | |
this.table = new Array(137); | |
this.betterHash = betterHash; | |
this.showDistro = showDistro; | |
this.put = put; | |
//this.get = get; | |
} | |
function put(data) { | |
var pos = this.betterHash(data); |
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
// LinkedList | |
function Node(element) { | |
this.element = element; | |
this.next = null; | |
} | |
function LList() { | |
this.head = new Node("head"); | |
this.find = find; | |
this.insert = insert; |