Sort

Sort a matrix or vector in place.

bool vector::Sort(
  ENUM_SORT_MODE mode      // sorting direction, SORT_ASCENDING or SORT_DESCENDING
   );
 
bool matrix::Sort(
  ENUM_MATRIX_AXIS axis,   // sorting axis
  ENUM_SORT_MODE mode      // sorting direction, SORT_ASCENDING or SORT_DESCENDING
   );

Parameters

axis

[in] Axis along which to sort. Set using a value of the ENUM_MATRIX_AXIS enumeration: AXIS_HORZ — sort horizontal elements, AXIS_VERT — sort vertical elements, or AXIS_NONE - sort all elements.

mode

[in] Sorting direction, ENUM_SORT_MODE::SORT_ASCENDING or ENUM_SORT_MODE::SORT_DESCENDING.

Return Value

Returns true on success; otherwise false, for example, if an invalid parameter is passed or the vector/matrix is empty.

Note

Sorting is performed in place — it is applied to the data of the matrix/vector for which the Sort method is called.

Example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
 //--- fill the vector
 vector v=vector::Random(10);
 //--- sort ascending
 v.Sort(SORT_ASCENDING);
 Print(v);
 // sort descending
 v.Sort(SORT_DESCENDING);
 Print(v);
 }