#include#include
int main() { // Create a list std::list myList = {1, 2, 3, 4, 5}; // Insert a single element at the beginning myList.insert(myList.begin(), 0); // Insert multiple elements at the end std::vector newElements = {6, 7, 8}; myList.insert(myList.end(), newElements.begin(), newElements.end()); // Insert multiple elements at a specific position myList.insert(myList.begin() + 3, 10, 0); // Print the elements in the list for(int num : myList) std::cout << num << " "; return 0; }
0 1 2 3 0 0 0 4 5 6 7 8The std list insert function belongs to the C++ Standard Library package.