DYNAMIC ARRAY as class / DYNAMIC ARRAY methods |
Adds a new element to the end of the array.
appendElement( )
This method creates a new element at the end of the array.
The element is initialized to NULL.
MAIN DEFINE a DYNAMIC ARRAY OF INTEGER ... (array has already 10 elements) CALL a.appendElement() LET a[a.getLength()] = a.getLength() DISPLAY a.getLength() -- shows 11 DISPLAY a[10] -- shows 10 DISPLAY a[11] -- shows 11 END MAIN
Since element allocation occurs automatically for dynamic arrays, you can omit the call the appendElement() method and assign directly the new element:
MAIN DEFINE a DYNAMIC ARRAY OF INTEGER LET a[100] = 87234 -- Array gets a length of 100 automatically LET a[101] = 98562 -- New element at position 101 END MAIN