Lesson 3.2

Cards (20)

  • Creating C++ List

    include the list header file in the program, std::list<Type> list_name = {value1, value2, ...}
  • Map
    • Associated containers holding key-value pairs, unique key for each pair
  • Basic Operations of the List
    • front() - returns the first element of the list
    • back() - returns the last element of the list
  • Vector Initialization
    std::vector<T> vector_name = {value1, value2, ...}
  • List

    • Dynamically grows in size, elements connected using doubly linked nodes, bidirectional iteration, no random access, efficient insertion and deletion
  • Vector Declaration
    std::vector<T> vector_name
  • Vector
    • Dynamically grows in size, stores elements of the same type, offers random access, automatically adjusts size, part of C++ Standard Template Library
  • Basic Vector Operations
    • Add elements
    • Access elements
    • Change elements
    • Remove elements
  • Creating a C++ STL Queue
    queue<type> q;
  • Creating a Stack
    stack<type> st;
  • Set
    STL containers that store unique elements of the same type in a sorted manner
  • Map
    Associated containers that hold pairs of data with unique keys
  • Queue
    Data structure that follows the FIFO principle
  • Stack
    Data structure that follows the LIFO principle
  • Basic Operations of the List
    1. front() - returns the first element of the list
    2. back() - returns the last element of the list
  • Map Methods
    1. insert() adds an element (key-value pair) to the map
    2. erase() removes an element or range of elements from the map
    3. clear() removes all the elements from the map
    4. find() searches the map for the given key
    5. size() returns the number of elements in the map
    6. empty() returns true if the map is empty
  • List
    Container that stores elements
  • Creating a Map
    1. std::map<key_type, value_type> map_name = {{key1, value1},{key2, value2}, ...};
    2. std::map - declares an STL container of type map
    3. <key_type> - the data type of the keys to be stored in the map
    4. <value_type> - the data type of the values to be stored in the map
    5. map_name - a unique name given to the map
    6. key1, key2, ... - keys to be stored in the map
    7. value1, value2, ... - values to be stored in the map
  • C++ Queue Methods
    1. push() - Inserts an element at the back of the queue
    2. pop() - Removes an element from the front of the queue
    3. front() - Returns the first element of the queue
    4. back() - Returns the last element of the queue
    5. size() - Returns the number of elements in the queue
    6. empty() - Returns true if the queue is empty
  • Creating a Set
    1. std::set<data_type> set_name = {key1, key2, key3, ...};
    2. std::set - declares an STL container of type set
    3. <data_type> - the data type of the values to be stored in the set
    4. set_name - a unique name given to the set
    5. key1, key2, key3, ... - key/value to be stored in the set