CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <list>
using namespace std;
int main() {
list<int> x({1,2,3,4,5});
//first element
x.front(); //return 1
//last element
x.back(); //return 5
//Construct and insert element at beginning
x.emplace_front(9); // now first element is 9
//Construct and insert element at the end
x.emplace_back(8); // now last element is 8
//Insert element at beginning
x.push_front(7); // first element is 7
//Add element at the end
x.push_back(6); //last element is 6
//Delete first element
x.pop_front(); //first element will be 9 again
//Delete last element
x.pop_back(); // now last element is 8 again
//emplace will put a value to a position
x.emplace(x.end(),0);
cout << x.front() << endl ;
cout << x.back();
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run