ARS. - Array Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > ARS. - Array's > !ARS. - Array Sorting >

ARS. - Array Operations

ARS.BinInsert

Previous Top Next


MiniRobotLanguage (MRL)

 

ARS.BinInsert

Inserts a value into a sorted array at the correct position to maintain sorting.

 

 

Intention

 

The ARS.BinInsert command inserts a value into a sorted array at the correct position to maintain the array's sorted order. This command uses a binary search algorithm to find the correct insertion point, making it efficient for large arrays.

 

Illustration:

Before ARS.BinInsert:

[1, 3, 5, 7]

After ARS.BinInsert|$$ARS|4:

[1, 3, 4, 5, 7]

 

Syntax

 

ARS.BinInsert|$$ARS|$$VAL

 

 

Parameter Explanation

 

P1 - $$ARS (Variable)

This variable holds the handle of the sorted array where the value will be inserted.

 

P2 - $$VAL (Variable or Value)

The value or variable containing the value to be inserted into the array.

 

 

Example

 

'***********************************

' ARS.BinInsert - Sample 1

'***********************************

ARS.New|$$ARR

ARS.Add|$$ARR|10

ARS.Add|$$ARR|20

ARS.Add|$$ARR|30

ARS.BinInsert|$$ARR|25

ARS.Show|$$ARR

' Output: [10, 20, 25, 30]

ENR.

 

'***********************************

' ARS.BinInsert - Sample 2

'***********************************

ARS.New|$$ARR

ARS.Add|$$ARR|"Apple"

ARS.Add|$$ARR|"Banana"

ARS.Add|$$ARR|"Cherry"

ARS.BinInsert|$$ARR|"Blueberry"

ARS.Show|$$ARR

' Output: ["Apple", "Banana", "Blueberry", "Cherry"]

ENR.

 

'***********************************

' ARS.BinInsert - Sample 3

'***********************************

ARS.New|$$ARR

ARS.Add|$$ARR|1.1

ARS.Add|$$ARR|2.2

ARS.Add|$$ARR|3.3

ARS.BinInsert|$$ARR|2.5

ARS.Show|$$ARR

' Output: [1.1, 2.2, 2.5, 3.3]

ENR.

 

 

Remarks

 

-

 

 

Limitations:

- The array must be sorted before using this command.

 

See also:

 

    ARS.New

    ARS.Sort