如何解决使链接列表的每个节点都有自己的链接列表
所以我试图制作一个“播放列表”程序,其中每个艺术家的名字都存储在一个艺术家链接列表的自己的节点中,然后每个艺术家都有自己的链接列表,其中每个节点都是该艺术家的歌曲。我的程序能够创建一个艺术家列表,但是我不知道如何将歌曲列表连接到艺术家列表的节点。有人可以帮我了解我的班级或“添加歌曲”功能的外观吗?
#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。我故意不使用字符串。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。