codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ list

C++ list

Doubly linked list.

A list inserts and removes anywhere in constant time, but has no [] access. Use push_front and push_back.

Example code

#include <iostream>
#include <list>
using namespace std;
int main() {
  list<int> l = {2, 3};
  l.push_front(1); l.push_back(4);
  for (int x : l) cout << x << " ";
  cout << endl;
  return 0;
}

Run this code in the online editor

← C++ STL and vectorsC++ stacks and queues →