Node Class inside the LinkedList class

c++, linked-list

Solution

I would do it like this

class LinkedList {
  private:
    struct Node {
        int data;
        Node* next;  
        Node* prev;
    };
    Node* head;
  public:
    ...
};

No need for anything in Node to be private since it's not useable outside of LinkedList.

Problem

I want to create a class of LinkedList and I have to put the class of Node inside of the class of LinkedList, how do you prefer me to do it? I think something like: ``` Class LinkedList { private: class Node* head; public: class Node { private: int data; Node* next; Node* prev; }; }; ``` but I think this is not good.

Original source