print elements of linked list
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
void printLinkedList(Node* head) {
while (head != nullptr) {
cout << head->data << " ";
head = head->next;
}
}
int main() {
Node* head = new Node{1, nullptr};
head->next = new Node{2, nullptr};
head->next->next = new Node{3, nullptr};
printLinkedList(head);
return 0;
}