fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef struct node {
  5. int data;
  6. struct node *next;
  7. } Node;
  8.  
  9. void traverseLinkedList(Node *start) {
  10. while(start) {
  11. //printf("Node");
  12. cout << start->data << "->";
  13. start = start->next;
  14. }
  15. cout << "NULL" << endl;
  16. }
  17. int main() {
  18. Node *start = (Node*) malloc(sizeof(Node));
  19. Node *a = (Node*) malloc(sizeof(Node));
  20. Node *b = (Node*) malloc(sizeof(Node));
  21. start->data = 0;
  22. a->data = 1;
  23. b->data = 2;
  24. start->next = a;
  25. a->next = b;
  26. traverseLinkedList(start);
  27. traverseLinkedList(a);
  28. traverseLinkedList(b);
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0->1->2->NULL
1->2->NULL
2->NULL