Skip to content

Instantly share code, notes, and snippets.

@whoan
whoan / depth-first-search.cpp
Last active November 11, 2019 19:12
DFS traversals
class DFS {
enum Method {
PreOrder, InOrder, PostOrder
} method;
enum Direction {
LeftToRight, RightToLeft
} direction;
template <typename TreeNode>
@whoan
whoan / relation.php
Created December 2, 2016 07:50
Query constraints for an eager loading query
// suppose `brothers` has a user_id foreign key
class User extends Model
{
public function brothers() {
return $this->hasMany('App\Brother');
}
}
// bad way