//+------------------------------------------------------------------+
//| Introsort.mq5 |
//| 2019-2021, dimitri pecheritsa |
//| mql5.com/en/users/dmipec |
//|------------------------------------------------------------------|
//| c| array sorting algorithm |
//| introsort or introspective sort is a hybrid sorting algorithm |
//|that provides both fast average performance and (asymptotically) |
//|optimal worst-case performance. it begins with quicksort, it |
//|switches to heapsort when the recursion depth exceeds a level |
//|based on (the logarithm of) the number of elements being sorted |
//|and it switches to insertion sort when the number of elements is |
//|below some threshold. this combines the good parts of the three |
//|algorithms, with practical performance comparable to quicksort on |
//|typical data sets and worst-case o(n log n) runtime due to the |
//|heap sort. since the three algorithms it uses are comparison |
//|sorts, it is also a comparison sort. |
//| introsort was invented by david musser in 1997, in which he also|
//|introduced introselect, a hybrid selection algorithm based on |
//|quickselect (a variant of quicksort), which falls back to median |
//|of medians and thus provides worst-case linear complexity, which |
//|is optimal. both algorithms were introduced with the purpose of |
//|providing generic algorithms for the c++ standard library which |
//|had both fast average performance and optimal worst-case |
//|performance, thus allowing the performance requirements to be |
//|tightened. introsort is in place and not stable |
//| the most popular c++ stl algorithm sort() uses introsort. |
//|------------------------------------------------------------------|
//| scr| introsort example |
//+------------------------------------------------------------------+
#include <Mqh\Algorithms\SortIntro\Introsort.mqh>
#include <Mqh\Algorithms\SortIntro\Functions.mqh>
void OnStart()
{
int a[] = {3, 1, 23, -9, 233, 23, -313, 32, -9};
ArraySort(a,new CIntroSort<int,int>,SORT_ORDER_ACCENDING);
ArrayPrint(a);
}
//+------------------------------------------------------------------+
//| >>>| -313 -9 -9 1 3 23 23 32 233 |
//+------------------------------------------------------------------+
#33475LibrariesMetaTrader 5👁 4667 views
introsort - array sorting algorithm
D
Author
DMITRII PECHERITSAPublished date
Feb 10, 2021
📚Related Articles
← View other articles →#77531Libraries
CSetupLedger: a per-setup win rate ledger for Expert Advisors
Why I wrote it My scalper trades two setups. A bullish order block and the bearish mirror of it. The Strategy Tester gave me one profit factor for both of them. I spent two weeks t...
Ali AkbarView detail →
#77488Libraries
Position sizing from risk, using the broker's own tick value and volume step
Every lot size calculator that assumes one pip is worth ten dollars is wrong on gold, wrong on indices, wrong on JPY crosses and wrong on any account not denominated in USD which i...
Ralph Ivan SimeonView detail →
#77156Libraries
PropFirm Defense
A prop firm account runs under a second rulebook MetaTrader 5 knows nothing about: a maximum loss measured from a fixed starting balance, a daily limit that resets at an hour the b...
Bruno Nunes Myrrha RibeiroView detail →