Types of Linked List | C ++ program to illustrate creation and traversal of Singly Linked List ; Structure of Node ; Function to print the content of linked list starting from the given node ; Iterate till n reaches NULL ; Print the data ; Driver Code ; Allocate 3 nodes in the heap ; Assign data in first node ; Link first node with second ; Assign data to second node ; Assign data to third node
#include <bits/stdc++.h> NEW_LINE using namespace std ; class Node { public : int data ; Node * next ; } ; void printList ( Node * n ) { while ( n != NULL ) { cout << n -> data << " ▁ " ; n = n -> next ; } } int main ( ) { Node * head = NULL ; Node * second = NULL ; Node * third = NULL ; head = new Node ( ) ; second = new Node ( ) ; third = new Node ( ) ; head -> data = 1 ; head -> next = second ; second -> data = 2 ; second -> next = third ; third -> data = 3 ; third -> next = NULL ; printList ( head ) ; return 0 ; }