In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, a container is a
class or a
data structure
In computer science, a data structure is a data organization, management, and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the rel ...
[Entry ''data structure'' in the ]Encyclopædia Britannica
The ( Latin for "British Encyclopædia") is a general knowledge English-language encyclopaedia. It is published by Encyclopædia Britannica, Inc.; the company has existed since the 18th century, although it has changed ownership various ...
(2009
Online entry
Accessed 4 Oct 2011. whose instances are collections of other objects. In other words, they store objects in an organized way that follows specific access rules.
The size of the container depends on the number of objects (elements) it contains. Underlying (inherited) implementations of various container types may vary in size, complexity and type of language, but in many cases they provide flexibility in choosing the right implementation for any given scenario.
Container data structures are commonly used in many types of
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
s.
Function and properties
Containers can be characterized by the following three properties:
* ''access'', that is the way of accessing the objects of the container. In the case of arrays, access is done with the array index. In the case of stacks, access is done according to the
LIFO (last in, first out) order and in the case of queues it is done according to the
FIFO (first in, first out) order;
* ''storage'', that is the way of storing the objects of the container;
* ''traversal'', that is the way of traversing the objects of the container.
Container classes are expected to implement
CRUD-like methods to do the following:
* create an empty container (constructor);
* insert objects into the container;
* delete objects from the container;
* delete all the objects in the container (clear);
* access the objects in the container;
* access the number of objects in the contai