1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <list>
int main() {
std::list<int> numbers = {1, 2, 3, 4, 5};
numbers.push_front(0); // Add to the beginning
numbers.push_back(6); // Add to the end
std::cout << "Size: " << numbers.size() << std::endl;
// Iterating
for (int num : numbers) {
std::cout << num << " ";
}
std::cout << std::endl;
// Accessing front and back
std::cout << "Front: " << numbers.front() << std::endl;
std::cout << "Back: " << numbers.back() << std::endl;
return 0;
}
Back to list