I want to implement a <<singly linked list in a singly linked list>> data structure. I coded my singly linked list but I find it difficult to make each node of the list behaving like a linked list itself. My node class code is given below (I have made everything public to avoid getters and setters):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class node { // creates the nodes
public:
int key;
int data;
node* next;
node(){ /
key = 0;
data = 0;
next = NULL;
}
node(int k, int d) {
key = k;
data = d;
next = NULL;
}
};
and a second class to build the linked list by connecting and manipulationg the nodes:
One thought of mine is to create one more class (class data) and set calss data in the class node (instead of int data),and to write a code similar to the code of the class singlylinkedlist but this time it is going to manipulate the class data similar to what class singlylinkedlist does for the class nodes, and therefore to create a list of data within each node.
Does this sound ok or is it nonsense? Any opinions are welcome..