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
/* | |
* This is the very basic implementation of Singleton | |
* Since C++11, this implementation is thread-safe | |
*/ | |
class Singleton { | |
public: | |
static Singleton& getInstance() { | |
static Singleton instance; | |
return instance; |
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
#include<sstream> | |
namespace std { | |
#ifndef to_string // gcc patch to_string | |
template <typename T> | |
string to_string(T value) | |
{ | |
std::ostringstream os ; | |
os << value ; |
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
template <typename T> | |
class Type { | |
public: | |
Type() {} | |
virtual ~Type() {} | |
virtual T* allocate() const { return new T; } | |
virtual T* cast(void *object) const { return static_cast<T*>(object); } | |
}; |
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
/*Author: Gelidus(gelidus@hotmail.sk)*/ | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
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
### | |
Sorting algorithm created by Gelidus January 1st | |
This algorithms uses two cycles to sort the given array correctly. | |
First, it will partially sort given sequence to the subsequences. | |
After that, it will simply compare first element with others to | |
correct the partial sort | |
@author: Peter "Gelidus" Malina - gelidus@hotmail.sk | |
@license: Do what you want |
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
int *selectionSort(int *array, int count) { | |
// at is location of first unordered item, minimum is unordered list minimum | |
int at = 0, minimum = 0; | |
for(at = 0; at < count-1; at++) { | |
minimum = at; // set minimum to the current replacer | |
for(int i = at+1; i < count; i++) { // find minimum | |
if(array[i] < array[minimum]) { |
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
int *bubbleSort(int *array, int count) { | |
int unsorted = count; // number of unsorted elements in array | |
bool swapped = false; | |
while(unsorted > 1) { | |
swapped = false; | |
for(int i = 0; i < unsorted-1; i++) { | |
if(array[i] > array[i+1]) { | |
// swap |
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
void swap(int *a, int *b) { | |
int temp = *a; | |
*a = *b; | |
*b = temp; | |
} | |
int *insertionSort(int *array, int count) { | |
for(int i = 1; i < count; i++) { // start at the second element | |
int replacer = i; |
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
### | |
Parses given array of input arguments and recognizes commands, | |
subcommands and switches with their values | |
@param [argv] argument list to parse | |
@return [ Array, Object] An array of commands and object of switches | |
### | |
parseArguments = (argv) -> | |
commands = [] | |
switches = { } |
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
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
template <typename T> | |
vector<T> *findDuplicates(T *elements, unsigned int length) { | |
sort(elements, elements + length); |
OlderNewer