Selection Sort - Array Sorting Algorithm - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources
//+------------------------------------------------------------------+ //| selection sort.mq5 | //| 2019-2021, Dimitri Pecherica| //| mql5.com/en/users/dmipec | mql5.com/en/users/dmipec | //+------------------------------------------------------------------+ //|Selection sort - array sorting algorithm | //+------------------------------------------------------------------+ //| Best: n^2, average: n^2, worst: n^2 | //| Memory: 1, Stable: No, Method: Select | //| NOTE: Stable when using O(n) extra space or using linked lists. | //+------------------------------------------------------------------+ //| In computer science, selection sort is an in-place comparison | //|Sort algorithm. Its time complexity is o(n2), which makes | //|It is inefficient on large lists and generally performs worse than | //|Similar to insertion sort. Selection sort is famous for its | //|Simple and has performance advantages over more complex ones| //|Algorithms in some cases, especially auxiliary | //|Memory is limited. | //| The time efficiency of selection sort is quadratic, so there is | //|There are some better sorting techniques | //|More complex than selection sort. One thing that’s different | //|The difference between selection sort and other sorting algorithms is that it makes | //|Minimum possible number of exchanges, n − 1 in the worst case. | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //|Script program startup function | //| [Using] selection sort example. Sort by trading type | //+------------------------------------------------------------------+ #include#include Blank on startup ( blank ) { //--- Start loading transactions from the terminal //2021 to present. They will be treated as an array of items //Sorter own transaction[]; Transaction Load(Transaction, D'2021.01.01' , 0 ); //--- Create a key array containing the symbol of each transaction //From the deals array, this is the basic string symbol for sorting []; DealsKeySymbol(deals, symbol); //--- Sort deals in descending order according to the selected symbol //Sorting algorithm array sort (symbol, transaction, new CSelectionSort< string , oolong >, false ); //--- Check the sorting results by printing the symbol table. //Your table will look different transaction print(transaction); } //------------------------------------------------------------------------------------------------ // Transaction|Token //------------------------------------------------------------------------------------------------ // 170477949 | Gold Dollar // 170764903 |Golden Dollar // 170764902 |Golden Dollar // 170252156 | Gold Dollar // 170541532 |Golden Dollar // 172313700 | Bitcoin USD // 172313699 | Bitcoin USD // 172313666 | Bitcoin USD // 172313530 | Bitcoin USD // 172313512 | Bitcoin USD // 172313511 | Bitcoin USD // 172313502 | Bitcoin USD // 172313501 | Bitcoin USD // 172313500 | Bitcoin USD // 172313493 | Bitcoin USD // 172313490 | Bitcoin USD // 172313488 | Bitcoin USD // 172313474 | Bitcoin USD // 172313453 | Bitcoin USD // 172313412 | Bitcoin USD // 171147845 | Bitcoin USD // 171145409 | Bitcoin USD // 171145256 | Bitcoin USD // 171145029 | Bitcoin USD // 171011667 | Bitcoin USD // 170983807 | Bitcoin USD // 170720576 | Bitcoin USD // 170429897 | Bitcoin USD // 169998112 | Bitcoin USD // 169998099 | Bitcoin USD // 169990154 | Bitcoin USD // ------------------------------------------------------------------------------------------------
Attachment download
📎 selectionsort.mq5 (6.11 KB)
📎 selectionsort.mqh (7.91 KB)
📎 functions.mqh (5.53 KB)
📎 asorter.mqh (3.12 KB)
📎 comparefunction.mqh (12.28 KB)
Source: MQL5 #33104
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •