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 encrypt(text){ | |
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq') | |
var crypted = cipher.update(text,'utf8','hex') | |
crypted += cipher.final('hex'); | |
return crypted; | |
} | |
function decrypt(text){ | |
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq') | |
var dec = decipher.update(text,'hex','utf8') |
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 mergesort($arr){ | |
if(count($arr) == 1 ) return $arr; | |
$mid = count($arr) / 2; | |
$left = array_slice($arr, 0, $mid); | |
$right = array_slice($arr, $mid); | |
$left = mergesort($left); | |
$right = mergesort($right); | |
return merge($left, $right); | |
} | |
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 shellsort(array $arr) | |
{ | |
$n = sizeof($arr); | |
$t = ceil(log($n, 2)); | |
$d[1] = 1; | |
for ($i = 2; $i <= $t; $i++) { | |
$d[$i] = 2 * $d[$i - 1] + 1; | |
} | |
$d = array_reverse($d); |
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 quicksort(array $arr, $left, $right) | |
{ | |
$i = $left; | |
$j = $right; | |
$separator = $arr[floor(($left + $right) / 2)]; | |
while ($i <= $j) { | |
while ($arr[$i] < $separator) { | |
$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
function countingSort(array $arr) | |
{ | |
$n = sizeof($arr); | |
$p = array(); | |
$sorted = array(); | |
for ($i = 0; $i < $n; $i++) { | |
$p[$i] = 0; | |
} | |
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 selectionSort(array $arr) | |
{ | |
$n = sizeof($arr); | |
for ($i = 0; $i < $n; $i++) { | |
$lowestValueIndex = $i; | |
$lowestValue = $arr[$i]; | |
for ($j = $i + 1; $j < $n; $j++) { | |
if ($arr[$j] < $lowestValue) { | |
$lowestValueIndex = $j; | |
$lowestValue = $arr[$j]; |
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 | |
function bubbleSort(array $arr) | |
{ | |
$n = sizeof($arr); | |
for ($i = 1; $i < $n; $i++) { | |
for ($j = $n - 1; $j >= $i; $j--) { | |
if($arr[$j-1] > $arr[$j]) { | |
$tmp = $arr[$j - 1]; | |
$arr[$j - 1] = $arr[$j]; | |
$arr[$j] = $tmp; |
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
// Bubble sort | |
function bubbleSort(array $arr) | |
{ | |
$n = sizeof($arr); | |
for ($i = 1; $i < $n; $i++) { | |
for ($j = $n - 1; $j >= $i; $j--) { | |
if($arr[$j-1] > $arr[$j]) { | |
$tmp = $arr[$j - 1]; | |
$arr[$j - 1] = $arr[$j]; |