﻿//+------------------------------------------------------------------+
//|                                            sort_simple_array.mq5 |
//|                                        Copyright © 2025, Amr Ali |
//|                             https://www.mql5.com/en/users/amrali |
//+------------------------------------------------------------------+
#include "Introsort.mqh"

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   // Sorting string array in ascending order (default, no compare function)
   string stringArray[] = {"cherry", "apple", "date", "banana"};
   Introsort(stringArray);
   ArrayPrint(stringArray);

   // For sorting string array in descending order,
   // We define a pointer type to custom Less function.
   typedef bool (*pDescending)(string &left, string &right);
   Introsort(stringArray, (pDescending)Descending);
   ArrayPrint(stringArray);
  }
//+------------------------------------------------------------------+

// Custom Less function to sort in descending order.
bool Descending(string &left, string &right)
  { return left > right;  }
