Question: I have a problem sorting the music playlist in order using the single linked list concept in the c program. The program entered for sorting
I have a problem sorting the music playlist in order using the single linked list concept in the c program. The program entered for sorting is correct but I can't change nodes of a combination of title, artist, album instead of changing the only title. What I can change the program so that getting the exact output?
#include
void create(char title[],char artist[],char album[]) { node *new = (node *)malloc(sizeof(node)); strcpy(new->title , title); strcpy(new->artist, artist); strcpy(new->album, album); new->link = NULL; if(first==NULL) { first = new; last = new; } else { last->link = new; last = new; } }
void music_insert() { char tit[MAX],art[MAX],alb[MAX]; printf("Enter the song title : "); fflush(stdin); scanf("%s",tit); printf("Enter the song artist : "); scanf("%s",art); printf("Enter the song album : "); scanf("%s",alb); node *new = (node *)malloc(sizeof(struct song)); strcpy(new->title, tit); strcpy(new->artist, art); strcpy(new->album, alb); last->link = new; new->link = NULL; last = new; }
void title_sort() { int n=0; node *temp1 = first; char *temp2; if(temp1!=NULL) { while(temp1) { if(strcmp(temp1->title,temp1->link->title)>0) { strcpy(temp2,temp1->title); strcpy(temp1->title,temp1->link->title); strcpy(temp1->link->title,temp2); } temp1=temp1->link; } }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
