-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_of_playlist_editor.c
More file actions
294 lines (275 loc) · 7.28 KB
/
code_of_playlist_editor.c
File metadata and controls
294 lines (275 loc) · 7.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*Music Playlist Editor By Rohin Vaidya and Shivam Yadav - Fr. Conceicao Rodrigues College Of Engineering ,Bandra,Mumbai,India */
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
struct song
{
char title[15];
char artist[10];
float duration;
};
struct song_node
{
struct song s;
struct music *next;
struct music *prev;
};
struct song_node *create_song()
{
float d;
struct song_node *newnode;
newnode=(struct song_node *)malloc(sizeof(struct song_node));
printf("Enter title and artist\n");
scanf("%s %s",newnode->s.title,newnode->s.artist);
printf("Enter duration of song\n");
scanf("%f",&d);
newnode->s.duration=d;
newnode->next=newnode->prev=NULL;
return (newnode);
}
struct song_node *defaultplay(struct song_node *head)
{
int i;
struct song s1[5]={{"KYE","Green Day",5.0},{"AI","Green Day",5.5},{"Faded","A. Walker",6.0},{"Spectre","Alan Walker",4.0},{"Shelter","Porter R.",6.3}};
printf("\nPlease enter the first song\n");
head=create_song();
struct song_node *temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
for (i=0;i<5;i++)
{
struct song_node *newnode;
newnode=(struct song_node *)malloc(sizeof(struct song_node));
strcpy(newnode->s.title,s1[i].title);
strcpy(newnode->s.artist,s1[i].artist);
newnode->s.duration=s1[i].duration;
newnode->prev=temp;
temp->next=newnode;
temp=temp->next;
}
return(head);
}
void display(struct song_node *head)
{
struct song_node *temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
while (temp!=NULL)
{
printf("\nTitle: %s\n",temp->s.title);
printf("Artist: %s\n",temp->s.artist);
printf("Duration: %f\n",temp->s.duration);
temp=temp->next;
}
}
/*struct song_node *shuffle(struct song_node *head)
{
struct song so;
int i,sh1,sh2,count,n;
i=1;sh1=1;sh2=5;
count=1;
n=no_of_songs(head);
struct song_node *temp1,*temp2;
temp1=temp2=head;
while(i<n/2)
{
while(count<=sh1)
{
temp1=temp1->next;
count++;
}
count=1;
while(count<=sh2)
{
temp2=temp2->next;
count++;
}
so=temp1->s;
temp1->s=temp2->s;
temp2->s=so;
i++;sh1++;sh2--;
}
display(head);
return(head);
}
*/
void play(struct song_node *head)
{
int i,count;
i=1;
struct song_node *t;
t=(struct song_node *)malloc(sizeof(struct song_node));
t=head;
printf("\nHow many songs would you like to play?\n");
scanf("%d",&count);
while(i<=count)
{
printf("\nTitle: %s\n",t->s.title);
printf("Artist: %s\n",t->s.artist);
printf("Time Elasped: %f\n",t->s.duration);
t=t->next;
i++;
}
}
void play_previous(struct song_node *head)
{
struct song_node *t1;
t1=(struct song_node *)malloc(sizeof(struct song_node));
t1=head;
while(t1!=NULL)
{
printf("\nTitle: %s\n",t1->s.title);
printf("Artist: %s\n",t1->s.artist);
printf("Duration: %f\n",t1->s.duration);
t1=t1->prev;
}
}
int no_of_songs(struct song_node *head)
{
int count=0;
struct song_node *tmp;
tmp=(struct song_node *)malloc(sizeof(struct song_node));
tmp=head;
while(tmp!=NULL)
{
tmp=tmp->next;
count++;
}
return(count);
}
struct song_node *insert_begin(struct song_node *head)
{
struct song_node *temp,*newnode;
temp=(struct song_node *)malloc(sizeof(struct song_node));
newnode=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
newnode=create_song();
newnode->next=temp;
temp->prev=newnode;
head=newnode;
return (head);
}
struct song_node *insert_end(struct song_node *head)
{
struct song_node *temp,*newnode;
temp=(struct song_node *)malloc(sizeof(struct song_node));
newnode=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
newnode=create_song();
newnode->prev=temp;
temp->next=newnode;
newnode->next=NULL;
return(head);
}
struct song_node *insert_at_position(struct song_node *head,int p)
{
struct song_node *newnode,*temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
newnode=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
newnode=create_song();
int pos;
pos=1;
while(pos<p)
{
temp=temp->next;
pos++;
}
newnode->next=temp->next;
newnode->prev=temp;
temp->next=newnode;
return(head);
}
struct song_node *remove_begin(struct song_node *head)
{
struct song_node *temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
head=temp->next;
head->prev=NULL;
return(head);
}
struct song_node *remove_end(struct song_node *head)
{
struct song_node *previous,*temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
while(temp->next!=NULL)
{
previous=temp;
temp=temp->next;
}
previous->next=NULL;
temp->next=temp->prev=NULL;
return(head);
}
struct song_node *remove_at_position(struct song_node *head,int p)
{
int pos;
pos=1;
struct song_node *previous,*temp;
temp=(struct song_node *)malloc(sizeof(struct song_node));
temp=head;
while(pos<=p)
{
previous=temp;
temp=temp->next;
pos++;
}
previous->next=temp->next;
temp->next=NULL;
return(head);
}
int main()
{
int ch,i,x,y;
struct song_node *head;
head=(struct song_node *)malloc(sizeof(struct song_node));
head=defaultplay(head);
printf("\n\t\t\t*****Default Playlist Has Been Created*****\n");
while (1)
{
printf("\n\t\t\t******Choose Your Operation******\n\t\t\t\t1.Display Playlist\n\t\t\t\t2.Shuffle Playlist\n\t\t\t\t4.Number of songs in the playlist\n\t\t\t\t5.Play Music\n\t\t\t\t6.Insert new song\n\t\t\t\t7.Remove a song\n\t\t\t\t8.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:display(head);
break;
case 2://head=shuffle(head);
break;
case 3:break;
case 4:x=no_of_songs(head);
printf("Total Songs: %d\n",x);break;
case 5: play(head);break;
case 6:
printf("\nWhere would you like to insert new song?\n\t1.At the start\n\t2.At the end\n\t3.At a position\n");
scanf("%d",&y);
switch(y)
{
case 1:head=insert_begin(head);break;
case 2:head=insert_end(head);break;
case 3:printf("\nEnter position at which song should be entered\n");
scanf("%d",&i);
head=insert_at_position(head,i);break;
}
break;
case 7:printf("\nWhich song would you like to delete?\n\t1.First\n\t2.Last\n\t3.At a position\n");
scanf("%d",&y);
switch(y)
{
case 1:head=remove_begin(head);break;
case 2:head=remove_end(head);break;
case 3:printf("\nEnter position at which song should be deleted\n");
scanf("%d",&i);
head=remove_at_position(head,i);break;
}break;
case 8:printf("\n\t\t\t\t*****Thank you for using our application*****\n");exit(0);
}
}
}
// End of the code copyrights Shivam and Rohin FRCRCE,Bandra,Mumbai,India @ 2018