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 power_set = function (set) { | |
| var array=[[]], | |
| sub_set = function(n,m) { | |
| // should return 2 dimensions array | |
| var result = []; | |
| if (m==1) { | |
| result.push([set[n]]); | |
| } else { | |
| for(var i=n, length=set.length; i<length-1; 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
| class MyArrayList | |
| def initialize n | |
| if n<0 then | |
| raise "size should be more than 0"; | |
| end | |
| @size=n | |
| @next_index=0 | |
| @innerArray=Array.new @size | |
| 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
| var suffix_array = (function(str){ | |
| var create_suffixes = function(arg_str) { | |
| var suffixes = []; | |
| for (var i=0, length=arg_str.length; i<length; i+=1) { | |
| var work=""; | |
| for (var j=i; j<length; j+=1) { | |
| work+=arg_str.charAt(j); | |
| } | |
| suffixes[i] = {string:work, index: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
| /* | |
| * circular-reference-detect.js | |
| * author: Hiroshi Kori | |
| * | |
| * Detect circular reference of linked list | |
| * | |
| * 1) Overview | |
| * - Reverse linked-list until finding a node whose next pointer is null. | |
| * - Chekck the head node if its next pointer is null | |
| * 1) null: the node is not traversed twice. (no circular reference) |
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 insertionSort = function(array) { | |
| for(var i=1, length=array.length; i<length; i+=1) { | |
| var insertion = array[i], j=i; | |
| if (insertion < array[i-1]) { | |
| do { | |
| array[j] = array[j-1]; | |
| j-=1; | |
| } while (array[j] > insertion && j > 0) | |
| array[j] = insertion; | |
| } |
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 selectionSort = function(array) { | |
| for(var i=0, length=array.length; i<length; i+=1) { | |
| var min_i = i; | |
| for(var j=i+1; j<length; j+=1) { | |
| if (array[j] < array[min_i]) { | |
| min_i = j; | |
| } | |
| } | |
| var small = array[min_i]; | |
| array[min_i] = array[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 combSort = function (array) { | |
| var interval = Math.floor(array.length/1.3); | |
| while (interval > 0) { | |
| for(var i=0; i+interval<array.length; i+=1) { | |
| if (array[i] > array[i+interval]) { | |
| var small = array[i+interval]; | |
| array[i+interval] = array[i]; | |
| array[i] = small; | |
| } | |
| } |
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 bubbleSort = function(array) { | |
| for (var i=0, length=array.length; i<length; i+=1) { | |
| for (var j=0; j<array.length-i-1; j+=1) { | |
| if (array[j]>array[j+1]) { | |
| var smallNum = array[j+1]; | |
| array[j+1]=array[j]; | |
| array[j]=smallNum; | |
| } | |
| } | |
| } |
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 sleepSort = function(array){ | |
| for (var i=0, length=array.length; i<length; i+=1) { | |
| setTimeout((function(n){ | |
| return function(){ | |
| console.log(n); | |
| }; | |
| })(array[i]), array[i]*100); | |
| } | |
| }; |
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
| import System.Environment | |
| import System.Directory | |
| import System.IO | |
| import Data.List | |
| import Control.Exception | |
| dispatch :: String -> [String] -> IO () | |
| dispatch "add" = add | |
| dispatch "view" = view | |
| dispatch "remove" = remove |