Professional Documents
Culture Documents
class Node {
public:
int data;
Node* next;
};
class LinkedList {
private:
Node* head;
public:
LinkedList() : head(nullptr) {}
if (head == nullptr) {
head = newNode;
} else {
temp = temp->next;
}
temp->next = newNode;
void display() {
temp = temp->next;
~LinkedList() {
head = head->next;
delete temp;
};
// Main function
int main() {
LinkedList list;
list.insert(1);
list.insert(2);
list.insert(3);
list.insert(4);
std::cout << "Elements of the list are: ";
list.display();
return 0;