Docsity

First Class Containers - Object Oriented Programming - Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download First Class Containers - Object Oriented Programming - Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object-Oriented Programming

(OOP)

Lecture No. 41

First-class Containers

  • Sequence and associative containers are

collectively referred to as the first-class

containers

…Container Adapters

  • stack
    • Last in first out (LIFO)
    • Can adapt vector , deque or list
  • queue
    • First in first out ( FIFO)
    • Can adapt deque or list
  • priority_queue
    • Always returns element with highest priority
    • Can adapt vector or deque

Common Functions for All

Containers

  • Default constructor
  • Copy Constructor
  • Destructor
  • empty()
    • Returns true if container contains no elements
  • max_size()
    • Returns the maximum number of elements

…Common Functions for All

Containers

  • operator <= ()
    • Returns true if the first container is less than or equal to the second container
  • operator > ()
    • Returns true if the first container is greater than the second container
  • operator >= ()
    • Returns true if the first container is greater than or equal to the second container

…Common Functions for All

Containers

  • operator == ()
    • Returns true if the first container is equal to the second container
  • operator != ()
    • Returns true if the first container is not equal to the second container
  • swap ()
    • swaps the elements of the two containers

…Functions for First-class

Containers

  • rbegin()
    • Returns an iterator object that refers to the last element of the container
  • rend()
    • Returns an iterator object that refers to the position before the first element

…Functions for First-class

Containers

  • erase( iterator )
    • Removes an element pointed to by the iterator
  • erase( iterator, iterator )
    • Removes the range of elements specified by the first and the second iterator parameters

Container Requirements

  • Each container requires element type to

provide a minimum set of functionality e.g.

  • When an element is inserted into a

container, a copy of that element is made

  • Copy Constructor
  • Assignment Operator

…Container Requirements

  • Associative containers and many

algorithms compare elements

  • Operator ==
  • Operator <