What is a dynamic array Also what is the syntax for one Can
What is a dynamic array? Also what is the syntax for one. Can you give me any info or tips that would be useful in implementing dynamic arrays.
Solution
Answer:
Dynamic array is a data structure which allows elements to be added or removed. It has a dynamic storage during its creation and it removes hectic process of manually management of memory. Dynamic arrays are allocated memory at the run time and memory is allocated from the heap.
Following is the code to implement the dynamic array :
int size ()
object get ( int index)
void add ( object obj )
void add ( int index object obj )
object remove ( int index )
First we get the size of the array. After that comes the index of each object and then we declare the object as obj. Then we give the index for each object. Whenever we want to remove and object from dynamic array we simply write object remove ( int index ).
