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
[alias] | |
brr = branch -r | |
br = branch | |
ci = commit -m | |
cia = commit -a -m | |
amend = commit --amend -C HEAD | |
co = checkout | |
cob = checkout -b | |
st = status -sb | |
me = merge --no-ff |
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
<?php | |
// O(n^2) | |
function selectionSort( array $array ) { | |
$length = count($array); | |
for ( $i = 0; $i < $length; $i++) { | |
$min = $i; | |
for( $j = $i + 1; $j < $length; $j++ ) { | |
if ( $array[$min] > $array[$j] ) |
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
<?php | |
// O(n^2) | |
function insertionSort( array $array ) { | |
$length = count($array); | |
for ( $i = 1; $i < $length; $i++ ) { | |
$j = $i; | |
while ( $j > 0 && $array[$j] < $array[$j-1] ) { | |
$temp = $array[$j]; | |
$array[$j] = $array[$j-1]; | |
$array[$j-1] = $temp; |
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
<?php | |
function mergeSort(array $array) { | |
$length = count( $array ); | |
// An array with one value is sorted | |
if ( $length < 2 ) | |
return $array; | |
// Split array in half | |
$left = $right = []; |
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 { | |
protected $top; | |
public function push($data) { | |
$node = new Node($data); | |
$node->next = $this->top; | |
$this->top = $node; | |
} |
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 LinkedList { | |
public $head; | |
public function add($data) { | |
$new_node = new Node($data); | |
if ( is_null( $this->head ) ) { | |
$this->head = $new_node; | |
} else | |
{ |
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
<?php | |
class BST { | |
protected $root; | |
/** | |
* Abstracts away root selection. | |
* | |
* @param $data | |
* @return BSTNode | |
* @throws Exception |
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
/** | |
* Childs game Tower of Hanoi with Stacks | |
* O(n^2) | |
* | |
* | |
* Disk layout | |
* | |
* 1|1 | | | |
* 2_|_2 | | | |
* 3__|__3 | | |
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
function DFS( $node, $data ) { | |
if ( $node->data == $data ) | |
return $node; | |
$new_node = null; | |
if ( !is_null( $node->left ) ) | |
$new_node = DFS($node->left, $data); | |
if ( !$new_node && !is_null( $node->right ) ) |
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
function getBit($binary_number, $byte_placement) { | |
return ( $binary_number & ( 1 << $byte_placement ) ) != 0; | |
} | |
function setBit( $binary_number, $byte_placement ) { | |
return $binary_number | ( 1 << $byte_placement ); | |
} | |
function clearBit( $binary_number, $byte_placement ) { | |
$mask = ~( 1 << $byte_placement ); |
OlderNewer