Inserts a value into a list at a specific position.
List.bdh
ListInsert( inout theList: list, in index: number, in element: union) : boolean;
| Parameter | Description |
|---|---|
| theList | List of number, boolean, float or string, which contains a copy of element at position index as an out parameter. |
| index | The position at which element will be inserted. |
| element | Number, boolean, float or string. Has to conform with the type of theList. |
transaction TAListInsert
var
lstNumber: list of number init 1, 2, 4, 5;
retVal1: boolean;
nr: number;
begin
nr := 3;
retVal1 := ListInsert(lstNumber, 3, nr);
if(retVal1 = true) then
nr := -1;
ListGetAt(lstNumber, 3, nr);
writeln("element at position 3: " + string(nr));
writeln("length of list: " + string(ListGetLength(lstNumber)));
else
writeln("ListInsert did not work!");
end;
end TAListInsert;
element at position 3: 3 length of list: 5