insert() / insertElement()

insert() inserts one array element into the specified position. This method requires two arguments.

If only one argument is provided, it is treated as the index and is added at the specified position.

InsertElement() inserts one empty element to a specified position. This method requires a single argument.

When an element is inserted, all the subsequent array elements are moved downwards. The dynamic array size increases by 1.

Syntax:

array_variable.insert(index ,[value])

array_variable.insertElement(index)

Usage example:

DEFINE ar DYNAMIC ARRAY OF INT
...
  FOR i = 1 TO 5                   #the array has 5 elements
    LET ar[i]=i
  END FOR
CALL ar.insert(2)                #inserts NULL as the second element, now array has 6 elements
CALL ar.insert(3, 1000)          #inserts 1000 as the third element, the array now has 7 elements

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.