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
#include <iostream> | |
#include <functional> | |
#include <algorithm> | |
#include <exception> | |
#include <stdexcept> | |
template<class T, class Less, class Greater> | |
class Node{ | |
public: | |
explicit Node(Less const& comparer, Greater const& greater); |
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
#include <iostream> | |
#include <memory> | |
template<class T> | |
class LessThan{ | |
public: | |
inline static bool apply(T const& a, T const& b){ | |
return a < b; | |
} | |
}; |
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 scala.annotation.tailrec | |
object Main extends App { | |
def QuickFindExample() { | |
var qu = QuickFind(10) | |
qu.union(1, 6) | |
qu.union(2, 6) | |
qu.union(2, 7) |
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
package examples.monads | |
case class User(id: Int, username: String, name: String) | |
trait UserRepository{ | |
def getById(id: Int) : Option[User] | |
def save(user: Option[User]) : Unit | |
} | |
trait UserService{ |
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
def foldLeft[T](l: List[T], initial: T, f: (T,T) => T) : T = { | |
def loop(v: List[T], accum: T) : T = { | |
l match{ | |
case Empty => accum | |
case Cons(head,tail) => loop(tail, f(head,accum)) | |
} | |
} | |
loop(l,initial) |
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
using System; | |
namespace Synergy | |
{ | |
public class Unit | |
{ | |
public static Unit Empty() | |
{ | |
return new Unit(); |
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
#include <iostream> | |
#include <stack> | |
#include <stdexcept> | |
#include <cctype> | |
#include <cstdlib> | |
using namespace std; | |
int evaluate(string const &expression){ | |
stack<char> operators; |
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
#include <iostream> | |
template<class T> | |
T three_sum(T values[], int N){ | |
T count = T(); | |
for(int i = 0; i < N; ++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
#include <iostream> | |
template<int N> | |
class quick_union{ | |
public: | |
quick_union() | |
{ | |
for(int i =0; i < N; ++i){ | |
elements[i] = i; | |
sizes[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
#include <iostream> | |
template<int N> | |
class quick_union{ | |
public: | |
quick_union() | |
{ | |
for(int i =0; i < N; ++i){ | |
elements[i] = i; | |
} |