Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar
💭
If I have seen further it is only by standing on the shoulders of giants. Newton

Adrian Statescu thinkphp

💭
If I have seen further it is only by standing on the shoulders of giants. Newton
View GitHub Profile
@thinkphp
thinkphp / map.c
Created September 14, 2017 07:13
Let's do a map-like function for C Language.
/**
* The question is: What are function pointers used for and how would I use them?
* A simple case is like this:
*
* You have an array of operations according to you business logic. You have
* a hashing function that reduces an input problem to one of the business logic functions.
* A clean code would have an array an array of function pointers, and your program
* will deduce an index to that array from the input and call it.
* One quit common use case is a callback function. For example if you load
* something from a DB you can implement your loading function so that it
@thinkphp
thinkphp / struct.euclid.go
Created September 12, 2017 14:08
Go by Example with struct, method and euclid
package main
import "fmt"
type Pair struct {
a, b int
}
func (n *Pair) euclid() int {
/**
* Adrian Statescu <mergesortv@gmail.com>
* StoogeSort implemented in c++.
*/
#include <iostream>
#include <fstream>
#include <vector>
#define FIN "algsort.in"
#define FOUT "algsort.out"
#define pb push_back
"""
Adrian Statescu <http://adrianstatescu.com>,<http://thinkphp.ro>
Binary Search with unitest
"""
import unittest
#iterative
def BinarySearch(arr, key):
lo, hi = 0, len(arr)-1
package main
import "fmt"
func findMax(vec []int, index int) int {
var iMax int
var i int
iMax = 0
@thinkphp
thinkphp / bubblesort-IO.go
Created September 1, 2017 03:22
Bubblesort implemented in Golang using IO FIle
package main
import ("fmt"
"io"
"os"
)
func outputFile(arr []int, n int) {
var i int
<?php
/**
* It's an algorithm for generating a random permutation of a finit sequence - in plain terms, the algorithm shuffles the sequence.
*
* Reference: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
*/
function MyShuffle(&$arr) {
@thinkphp
thinkphp / bubblesort_typename.cpp
Created August 28, 2017 08:15
Bubblesort using typename template
#include <iostream>
#include <fstream>
#include <vector>
using std::vector;
using std::cout;
using std::endl;
template<typename T>
void print(vector<T> l) {
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Sorting Methods: bubble sort, select by min,shell sort, quick sort, merge sort</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style>
html,body {background: #333;color: #ccc}
h1 {
background: #393;
font-family: helvetica,arial,verdana,sans-serif;
font-size: 350%;
#include <stdio.h>
#include <stdbool.h>
#include <malloc.h>
#define FIN "algsort.in"
#define FOUT "algsort.out"
#define pb push_back
typedef bool (*comparer)(const void *a, const void *b);
bool ascending_order(const void *a, const void *b) {