#include <iostream>
// Define a structure for a node in a linked list
struct Node {
int data; // Data stored in the node
Node* next; // Pointer to the next node in the list
};
int main() {
// Create three nodes
Node* firstNode = new Node;
Node* secondNode = new Node;
Node* thirdNode = new Node;
// Assign data to each node
firstNode->data = 1;
secondNode->data = 2;
thirdNode->data = 3;
// Link the nodes to form a linked list
firstNode->next = secondNode;
secondNode->next = thirdNode;
thirdNode->next = nullptr; // Mark the end of the list
// Traverse the linked list and print the data in each node
Node* currentNode = firstNode;
while (currentNode != nullptr) {
std::cout << currentNode->data << " ";
currentNode = currentNode->next;
}
// Clean up: free the memory allocated for the nodes
delete firstNode;
delete secondNode;
delete thirdNode;
return 0;
}