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
| /** | |
| * 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 |
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 main | |
| import "fmt" | |
| type Pair struct { | |
| a, b int | |
| } | |
| func (n *Pair) euclid() int { | |
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
| /** | |
| * 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 |
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
| """ | |
| 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 |
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 main | |
| import "fmt" | |
| func findMax(vec []int, index int) int { | |
| var iMax int | |
| var i int | |
| iMax = 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
| package main | |
| import ("fmt" | |
| "io" | |
| "os" | |
| ) | |
| func outputFile(arr []int, n int) { | |
| var i int |
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 | |
| /** | |
| * 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) { |
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 <fstream> | |
| #include <vector> | |
| using std::vector; | |
| using std::cout; | |
| using std::endl; | |
| template<typename T> | |
| void print(vector<T> l) { |
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
| <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%; |
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 <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) { |