<<< Linked List Design Models     Index     C++ Node class for singly-linked list >>>

4. C-style Linked List Example

  • C-style design model is using global functions and structs to hold data:

    
    //Node.h
    struct Node {
        int data;
        Node* next;
    };
    void insert_front(
        struct Node* node,
        struct Node* newNode )
    {
        newNode->next = node->next;
        node->next = newNode;
    }
    
    

      Singly-linked list insert_after

  •   Singly-linked list

    
    #include <cstddef>
    #include "Node.h"
    int main ( )
    {
        struct Node A;
        struct Node B;
        struct Node C;
    
        A.data = 12;
        B.data = 99;
        C.data = 37;
    
        insert_front( &A, &C );
        insert_front( &A, &B );
        C.next = NULL;
    
        return 0;
    }
    
    
<<< Linked List Design Models     Index     C++ Node class for singly-linked list >>>