Hi,

I was following the linked list tutorial on this site. I have the code here, but I am not sure if I am doing it right. Could someone tell me if I am on the right track, or is there a way I could do it better ?

Thanks in advance.

Code:#include <cstdio> #include <iostream> using namespace std; struct Node { int x; Node *next; }; void AddNode(Node *node, int value) { if(node != NULL) { while(node->next != NULL) { node = node->next; } } node->next = new Node; node = node->next; node->next = NULL; node->x = value; } void PrintValue(Node *node) { do { cout << node->x << endl; node = node->next; }while(node != NULL); } int main() { Node *root = new Node; root->next = NULL; root->x = 5; AddNode(root, 10); AddNode(root, 30); AddNode(root, 50); PrintValue(root); getchar(); return 0; }