#include#include using namespace std; int main() { list
myList; myList.push_front(5); // add 5 to the beginning of the list myList.push_front(7); // add 7 to the beginning of the list myList.push_front(9); // add 9 to the beginning of the list for (auto i = myList.begin(); i != myList.end(); i++) { cout << *i << " "; // Output: 9 7 5 } return 0; }
#includeIn this example, we create a list of `Student` objects. We then add two `Student` objects to the beginning of the list using the `push_front` function. Finally, we loop through the list and output the name of each student to the console. CPP list is a built-in package library in c++.#include using namespace std; class Student { public: string name; Student(string new_name) { name = new_name; } }; int main() { list
myClass; myClass.push_front(Student("Mathew")); // add Mathew to the beginning of the list myClass.push_front(Student("John")); // add John to the beginning of the list for (auto i = myClass.begin(); i != myClass.end(); i++) { cout << i->name << endl; // Output: John Mathew } return 0; }