#include<stdio.h> #include<conio.h> #include<stdlib.h> struct song{ char b[20]; struct song* prev; struct song* next; }; struct song* head; void insert(struct song** headptr){ struct song* newsong= (struct song*)malloc(sizeof(struct song)); struct song* ptr; printf("Enter a new song: "); scanf("%s",&newsong->b); newsong->prev=NULL; newsong->next=NULL; if(*headptr==NULL){ *headptr=newsong; newsong->next=*headptr; newsong->prev=*headptr; }else{ ptr=*headptr; while(ptr->next!=*headptr){ ptr=ptr->next; } ptr->next=newsong; newsong->next=*headptr; newsong->prev=ptr; (*headptr)->prev=newsong; } } void deletion(struct song** ptr){ struct song* temp; if((*ptr)->next==head && (*ptr)->prev==head){ head=NULL; printf("Song Deleted. Playlist is empty.\n"); } else if(*ptr==head){ temp=(*ptr); head=head->next; head->prev=temp->prev; temp->prev->next=head; printf("Song Deleted.\n"); }else if((*ptr)->next==head){ temp=(*ptr)->prev; temp->next=head; head->prev=temp; } } void display(struct song* head){ struct song *ptr=head; do{ printf("%s\n",ptr->b); ptr=ptr->next; }while(ptr!=head); } int main(){ int choice; struct song* ptr; do{ printf(" 1.Enter a New song\n 2.Display playlist\n 3. Play a song\n 4. Play next\n 5. Play previous\n 6.Exit\n 7.Delete this song"); printf("\nEnter your choice:- "); scanf("%d",&choice); switch(choice){ case 1: insert(&head); break; case 2: display(head); break; case 3: ptr=head; printf("Playing %s\n",ptr->b); break; case 4: ptr=ptr->next; printf("Playing %s\n", ptr->b);break; case 5: ptr=ptr->prev; printf("Playing %s\n", ptr->b); break; case 6: break; case 7: deletion(&ptr); break; default: printf("Wrong Input.\n"); } }while(choice!=6); getch(); return 0; }