struct songs
{
char* name[MAX];
double length;
struct songs *next;
};
typedef struct songs songs;
struct albums
{
char* title[MAX];
int year;
char* singerName[MAX];
songs songs;
struct albums *next;
};
struct albums *head = NULL;
struct albums *curr = NULL;
struct songs *bas=NULL;
struct songs *current=NULL;
我定义了结构。第二部分包含所有专辑的列表。第一部分包含歌曲列表。专辑中有歌曲。
void add(char albumTitle[],char singerName[], int releaseYear )
{
struct albums *temp;
temp=(struct albums *)malloc(sizeof(struct albums));
strcpy( temp->title, albumTitle );
temp->year=releaseYear;
strcpy( temp->singerName, singerName );
if (head== NULL)
{
curr=head=temp;
head->next=NULL;
curr->next=NULL;
}
else
{
curr->next=temp;
curr=temp;
}
printf("Done\n");
}
这部分用于添加相册。最后,
void addSong(char albumTitle[],char songName[], double songLength )
{
struct albums *temp;
temp=(struct albums *)malloc(sizeof(struct albums));
temp=head;
struct songs *tempsong;
tempsong=(struct songs *)malloc(sizeof(struct songs));
tempsong=bas=current;
while(temp!=NULL)
{
if(!(strcmp(temp->title, albumTitle)))
{
bas=temp->songs;
strcpy(tempsong->name,songName);
tempsong->length=songLength;
if (bas== NULL)
{
bas=tempsong;
bas->next=NULL;
current->next=NULL;
}
else
{
current->next=tempsong;
current=tempsong;
}
break;
}
else
{
temp= temp->next;
}
}
}
这部分需要为专辑添加歌曲。我的问题在这部分。如何在大链表中添加歌曲?非常感谢您的任何建议,