Programming Fundamentals/Dynamic Arrays

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Overview[edit]

A dynamic array is a random access,a variable-size list data structure that allows elements to be added or removed. It is supplied with standard libraries in many modern programming languages. Dynamic arrays overcome a limit of static arrays, which have a fixed capacity that needs to be specified at allocation.[1]

Discussion[edit]

A limitation of the static arrays discussed so far is that the array size is determined when the array is created and/or allocated. Dynamic arrays allow elements to be added and removed at runtime. Most current programming languages include built-in or standard library functions for creating and managing dynamic arrays.

Language Class Add Remove
C++ #include <list>
std::list
insert erase
C# System.Collections.Generic.List Add Remove
Java java.util.ArrayList add remove
JavaScript Array push, splice pop, splice
Python List append remove
Swift Array append remove

Key Terms[edit]

dynamic array
A data structure consisting of a collection of elements that allows individual elements to be added or removed.

References[edit]