#include#include using namespace std; int main (){ list
mylist {10, 20, 30, 40, 50}; mylist.push_back(60); for (auto it = mylist.begin(); it != mylist.end(); ++it) cout << *it << " "; return 0; }
#includeDescription: In this code example, a custom Node class is created to represent the elements of the LinkedList. The addNode() function is used to add a new node to the LinkedList given its head and new data. A LinkedList is created by calling addNode() four times to add nodes with data values 4, 3, 2, and 1. Finally, a while loop is used to iterate through the LinkedList and print its elements. Package/Library: Standard C++ Libraryusing namespace std; class Node { public: int data; Node* next; }; void addNode(Node** head, int new_data) { Node* new_node = new Node(); new_node->data = new_data; new_node->next = (*head); (*head) = new_node; } int main() { Node* head = NULL; addNode(&head, 4); addNode(&head, 3); addNode(&head, 2); addNode(&head, 1); Node* temp = head; while (temp != NULL) { cout << temp->data << " "; temp = temp->next; } return 0; }