Array-based list
The array-based list, also known as array list, is a resizable array implementation. Thus, as more elements are added to the linked list, its size increases dynamically. The array-based list assigns an element to the assigned array; however, if a new element is assigned some data, and there is no space in the array, then it allocates a new array, and moves all the data to the newly allocated array. For example, as shown in Figure 3.19, since the array is full, all of the data is reassigned to a bigger array by increasing the size by a default value.
Figure 3.19: Example array-based link list
Let us set up a reference class ALinkList
for an array list in R. To set up an array linked list, the class fields required are as follows:
Alist
: To store the datasetlistsize
: Pointer to the current location in the array; this can also be used to get the current list sizearraysize
: Default expansion sizemaxSize
: Maximum array size
The defined class initializes anĀ arraysize
of 100
...