53 lines
930 B
Markdown
53 lines
930 B
Markdown
# InsertSort
|
||||
|
|
|
|||
|
|
Inserts an element in a sorted array.
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
bool InsertSort(
|
|||
|
|
float element // element to insert
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
Parameters
|
|||
|
|
|
|||
|
|
element
|
|||
|
|
|
|||
|
|
[in] Value of the element to be inserted into a sorted array
|
|||
|
|
|
|||
|
|
Return Value
|
|||
|
|
|
|||
|
|
true - successful, false - cannot insert the element.
|
|||
|
|
|
|||
|
|
Example:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
//--- example for CArrayFloat::InsertSort(float)
|
|||
|
|
#include <Arrays\ArrayFloat.mqh>
|
|||
|
|
//---
|
|||
|
|
void OnStart()
|
|||
|
|
{
|
|||
|
|
CArrayFloat *array=new CArrayFloat;
|
|||
|
|
//---
|
|||
|
|
if(array==NULL)
|
|||
|
|
{
|
|||
|
|
printf("Object create error");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//--- add arrays elements
|
|||
|
|
//--- . . .
|
|||
|
|
//--- sort array
|
|||
|
|
array.Sort();
|
|||
|
|
//--- insert element
|
|||
|
|
if(!array.InsertSort(100.0))
|
|||
|
|
{
|
|||
|
|
printf("Insert error");
|
|||
|
|
delete array;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
//--- delete array
|
|||
|
|
delete array;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
```
|