Make each node of a Linked List have its own Linked List

172 Views Asked by At

so I'm trying to make a "playlist" program where each artist's name is stored in its own node of a Artist linked list and then each artist has their own Linked List where each node are Songs by the artist. My program is able to create a List of artists but I can't figure out how to connect the Songs List to the nodes of the Artist List. Can anyone help me with how my Class or how an Add Song function should look?

header

#include <iostream>
#include <cstring>
using namespace std;

struct songNode
{
    char* Title = new char[25];

    songNode* next;
    songNode()
    {
        next = 0;
    }
};

struct artistNode
{
    char* artistName = new char[25];

    artistNode* next;
    artistNode() 
    {
        next = 0;
    }
};

class artistClass
{
public:
    artistClass()            //constructor
    {
        head = NULL;
    }
    //~recordLabel();        //destructor   
    void addArtist(char* artistName);
    void displayArtists();
    void addSong();
private:
    //songNode* head; Should this be here?
    artistNode* head;
};

recordlabel.cpp

void artistClass::addArtist(char* artistName)  
{
    artistNode* temp = new artistNode;
    
    temp->artistName = new char[strlen(artistName) + 1];   //add artist name to node
    strcpy(temp->artistName, artistName);

    temp->next = head;
    head = temp;
}

P.S. I'm purposely not using Strings.

0

There are 0 best solutions below