C++ STL: lists

C++ STL: Lists


Lists allow constant time insert and erase operations anywhere within the container, and also lets iteration in both the directions.

Lists are implemented as doubly-linked lists. These perform awesomely in inserting, extracting and moving elements in any position within the container for which an iterator has already been obtained.

The main drawback of lists (and forward_lists) is that they lack direct access to the elements by their positions. If you want to access 8th element you must iterate all the way to this node. This takes linear time also it takes extra memory for containing links to next and previous nodes(or only next node in case of forward_lists).


Important Member Functions:

  • begin: Return an iterator to the beginning of the list
  • end: Return an iterator to end of the list
  • empty: Test whether the list is empty of not.
  • size: Return the size of the list.
  • front: access the first element.
  • back: access the last element
  • assign: assigns the content of one linked list to other
  • emplace_front: Construct and insert an element at the front of the list.
  • push_front: Inserts an element at the front of the list.
  • pop_front: Delete the first element of the list
  • emplace_back: Construct and insert an element at the end of the list.
  • push_back: Add element at the back of the list
  • pop_back: Delete the last element
  • emplace: Construct and insert an element at a position in the list.
  • insert: insert elements at a position
  • erase: erase either a single element at a position or a range of elements from the lists.
  • swap: swap contents of two lists
  • remove: remove elements with specific values
  • remove_if: remove elements fulfilling condition'
  • unique: remove duplicate values
  • merge: merge two sorted lists
  • sort: sort list
  • reverse: reverse the list.

Here is the link to the official documentation for lists in c++: http://www.cplusplus.com/reference/list/list/

No comments:

Post a Comment

Installing albert on ubuntu 19.04

Installing Albert on Ubuntu 19.04... Albert is not still released for ubuntu 19.04. But still, you can install it using the following ...