forked from lavinske/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongList
More file actions
119 lines (112 loc) · 2.42 KB
/
Copy pathSongList
File metadata and controls
119 lines (112 loc) · 2.42 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Song{
char title[50];
struct Song *next;
}*head, *tail, *curr;
void push_back(char title[]){
struct Song *temp = (struct Song*)malloc(sizeof(struct Song));
strcpy(temp->title, title);
temp->next = NULL;
if(!head){
head = tail = temp;
}
else{
tail->next = temp;
tail = temp;
}
}
void pop_front(){
if(!head) return;
curr = head;
head = head->next;
free(curr);
}
void view(){
if(!head){
printf("Oh no.. The queue is empty..\n"); return;
}
int n = 0;
curr = head;
while(curr){
printf("%2d) %s\n", ++n, curr->title);
curr = curr->next;
}
}
bool is_valid_music_number(int n){
if (n < 1||n > 10){
printf("ERROR: The music number must be between 1 and 10!\n");
return false;
}
return true;
}
int main(){
char song[][50] = {
"IDGAF - Dua Lipa",
"FRIENDS - Marshmello, Anne-Marie",
"The Middle - Zedd, Maren Morris, Grey",
"Best Part - H.E.R., Daniel Caesar",
"All The Stars (with SZA) - Kendrick Lamar, LZA",
"Wolves - Selena Gomez, Marshmello",
"God's Plan - Drake",
"Rewrite The Stars - Zac Efron, Zendaya",
"Havana - Camila Cabello, Young Thug",
"Perfect - Ed Sheeran"
};
int menu, music_num;
do{
system("cls");
printf("SONG LIST\n");
for (int i = 0; i < 10; i++){
printf("%2d) %s\n", i+1, song[i]);
}
printf("\nNEXT IN QUEUE\n");
view();
printf("\nMAIN MENU\n");
printf ("1. Add Music Into Queue\n"
"2. Next Music\n"
"3. Clear Queue\n"
"4. Exit\n");
do{
printf("Input your choice: ");
scanf("%d", &menu); getchar();
}while(menu < 1||menu > 4);
printf("\n");
switch(menu){
case 1:
do{
printf("What music number will be added into the queue [1..10] ? ");
scanf("%d", &music_num); getchar();
}while(!is_valid_music_number(music_num));
push_back(song[music_num-1]);
printf("The music \"%s\" is added to the queue!\n", song[music_num-1]);
getchar();
break;
case 2:
if(!head){
printf("Put some music into the queue first!\n");
}
else{
printf("Now Playing: %s\n", head->title);
printf("Press ANY KEY to STOP playing the music!\n");
pop_front();
}
getchar();
break;
case 3:
if(!head){
printf("Put some music into the queue first!\n");
}
else{
while(head){
pop_front();
}
printf("Your music queue has been cleared!\n");
}
getchar();
break;
}
}while(menu != 4);
return 0;
}