Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question has been asked twice before both answers are incomplete. Create a

ID: 3537907 • Letter: T

Question

This question has been asked twice before both answers are incomplete.

Create a linked list structure Music that contains the data fields Name, Artist, Number_of_Songs, and a pointer to the list. Create the structure with 3 members and fill in data for each member. Create a function that will display() all the data for each member and call it from the main program.

Previous anwers get an error from the "curr->next = head;" line says that you can't convert an item to a list and vice versa.

Also the previous answers only had two data fields vice the three the question specifies.

Explanation / Answer

#include<stdlib.h>

#include<stdio.h>

#include<string.h>


struct Music

{

char name[40];

char artist[40];

int number;

struct Music *next;

};


typedef struct Music music;


void insert(music **head,char *name,char *artist,int number)

{

music *temp;

temp=(music *)malloc(sizeof(struct Music));

if(!temp)

{

printf("no space ");

exit(1);

}

strcpy(temp->name,name);

strcpy(temp->artist,artist);

temp->number=number;

temp->next=*head;

*head=temp;

}


void display(music *head)

{

music *temp;

if(!head)

{

printf("no information ");

return;

}

temp=head;

while(temp)

{

printf("name:%-20s artist:%-20s number of songs:%-3d ",temp->name,temp->artist,temp->number);

temp=temp->next;

}

}


int main()

{

music *head=0;

insert(&head,"thriller","michael jackson",9);

insert(&head,"born sinner","J.Cole",10);

insert(&head,"Yeezus","Kanye West",7);

display(head);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote