Professional Documents
Culture Documents
Document
Document
h>
#include<stdlib.h>
#include<string.h>
Struct node*next;
Struct node*prev;
};
Char temp[40];
Struct node*head=NULL;
Struct node*current_node=NULL;
Void insert(){
While((getchar())!=’\n’);
Scanf(“%[^\n]%*c”,temp);
Struct node* new_node=(struct node*)malloc(sizeof(struct node));
Strcpy(new_node->data,temp);
If(head==NULL){
New_node->next=new_node->prev=new_node;
Head=current_node=new_node;
Return;
Struct node*last=head->prev;
New_node->prev=last;
Last->next=new_node;
New_node->next=head;
Head->prev=new_node;
}
Void Delete_element(){
If(head==NULL){
Return;
While((getchar())!=’\n’);
Scanf(“%[^\n]%*c”,temp);
Printf(“\n”);
Struct node*ptr=head;
Do{
Head=NULL;
Free(ptr);
Return;
Else if(strcmp(ptr->data,temp)==0){
Struct node*prev=ptr->prev;
Struct node*next=ptr->next;
Prev->next=next;
Next->prev=prev;
Head=next;
Free(ptr);
Printf(“Music deleted!\n”);
Return;
Ptr=ptr->next;
}while(ptr!=head);
Printf(“No Music file is there!\n”);
Void show(){
If(head==NULL){
Printf(“Playlist is Empty!\n”);
Return;
Struct node*show_ptr=head;
Printf(“\n”);
Int i=1;
Do{
Printf(“Song %d : %s\n”,I,show_ptr->data);
I++;
Show_ptr=show_ptr->next;
}while(show_ptr!=head);
Void next_node(){
If(current_node==NULL){
Else{
Current_node=current_node->next;
Void prev_node(){
If(current_node==NULL){
Else{
Current_node=current_node->prev;
Void first_node(){
If(head==NULL){
Printf(“Playlist is Empty!\n”);
Else{
Void last_node(){
If(head==NULL){
Printf(“Playlist is Empty!\n”);
Else{
Void specific_data(){
If(head==NULL){
Return;
}
While((getchar())!=’\n’);
Scanf(“%[^\n]%*c”,temp);
Printf(“\n”);
Struct node*ptr=head;
Do{
If(strcmp(ptr->data,temp)==0){
Printf(“Music Found!\n”);
Return;
Ptr=ptr->next;
}while(ptr!=head);
Printf(“There is no Music file with this name!\n”);
Int main(){
Int choice;
Menu:
Scanf(“%d”,&choice);
If (choice == 1)
Insert();
Else if (choice == 2)
Delete_element();
Else if (choice == 3)
Show();
Else if (choice == 4)
Next_node();
Else if (choice == 5)
Prev_node();
Else if (choice == 6)
First_node();
Else if (choice == 7)
Last_node();
Else if (choice == 8)
Specific_data();
Else
Exit(0);
Goto menu;
Return 0;
OUTPUT :
1. Add Music
2. Remove Music
3. Show Playlist
Playlist is Empty!
1. Add Music
2. Remove Music
3. Show Playlist
9. Exit