linked list within another linked list

I want to create a linked list of musical genres where each node is one genre of music (i.e. reggae, classical, rock, etc.). Within each node, I want to have another list of artists that fall under that specific genre.

My question is how do I get the list of artists into the nodes of the list of genres?

In my code, I have a class called Artist where I will manage the information (such as the artist's name, album names, number of albums, etc.) of one artist. Next, I created a node struct that will be used for the implementation of a linear linked list of artists. I created a class called Artist_List to manage the linked list of artists.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Artist
{
    private:
        char * name;
        char * albums[size];
        int num_of_albums;
    public:
        //functions to manage the creation of an artist
};

struct node
{
    Artist one_artist;
    node * next;
};

class Artist_list
{
    private:
        node * head;
    public:
        //functions to manage the linear linked list
};


I am confused on where to go from here. I can create a list of Genres the same way I do the list of Artists. However, how would I get the list of Artists into the nodes of the Genre list. Would the node struct for Genre contain another pointer, one that points to the list of Artists?

Any suggestions?

I don't need coding examples if it's too tedious to write (general examples, maybe), but an explanation or ideas of how I could solve this problem would greatly help!
Last edited on
To keep consistency with the overall structure you already have (which is not ideal, but I guess it's fine enough for an assignment), you should have a Genre_list that contains a pointer to a Genre_node, which itself contains a pointer to a Genre_node and a Genre. Genre should contain the relevant information for that genre, including an Artist_list. You can choose to use a pointer to an Artist_list instead, but you're already dealing with enough levels of indirection.
What would be a more ideal or direct way than what I have? I'm still in my brainstorming/planning process and I'm starting out with what's familiar. However, if there are easier, more efficient ways, I'd love to learn them. What would be a better approach?

Anyway, to my understanding, I am to create another class called Genre_List with a head pointer to Genre_node. Then within Genre_node are two pointers, one to another Genre_node and one to Genre. What is Genre?

So many pointers...
What would be a more ideal or direct way than what I have?
I'd prefer not to confuse you with unnecessary information, since I don't know what the parameters for your assignment/course are.

Then within Genre_node are two pointers, one to another Genre_node and one to Genre
This is valid, but to maintain consistency, this would be preferable:
1
2
3
4
struct Genre_node{
    Genre one_genre;
    Genre_node *next;
};


What is Genre?
I don't know. You should know that. At the very least, from what you've said, it should be
1
2
3
class Genre{
    Artist_list artists;
};
Last edited on
Okay, well thank you for the help. I think I have enough information to proceed further :)
Topic archived. No new replies allowed.