Collections of Data

Collections of Data

Arrays

  • An array is a structure that can hold a fixed-size sequential collection of elements of the same type.
  • Array indices are usually integer or pointer types.
  • Arrays have a fixed size, determined at declaration, and cannot be resized later.
  • The elements in an array may be accessed using their index; this is called indexing.

Lists

  • A list is an ordered collection of elements.
  • Unlike arrays, lists are dynamic, so they can grow and shrink at runtime.
  • The elements in a list can be any type, including custom objects.

Stacks and Queues

  • A stack is a collection of elements that supports fast last-in, first-out (LIFO) semantics for inserts and deletes.
  • A queue is a collection of elements that supports fast first-in, first-out (FIFO) semantics for inserts and deletes.
  • Stacks and queues are used in various types of data processing algorithms.

Maps

  • A map (also known as a dictionary or associative array) is a data structure that holds key-value pairs.
  • The keys are used to look up the corresponding values, making it highly efficient for this purpose.
  • The keys in a map are unique - no two keys can be the same.

Understanding these data collections and their appropriate uses in OOP is key to efficient data manipulation and access. Utilising different types of collections where appropriate can drastically improve the performance and readability of your code.