-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircularSongsPayer.cpp
99 lines (85 loc) · 2.04 KB
/
CircularSongsPayer.cpp
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
#include<iostream>
using namespace std;
struct MyHitCollections{
int id;
string name;
string singerName;
int year;
MyHitCollections*next;
MyHitCollections*prev;
};
MyHitCollections*head;
MyHitCollections*tail;
void AddSong(){
MyHitCollections*new_song;
new_song=new MyHitCollections();
cout<<"Enter Song Name : "; getline(cin,new_song->name);
cout<<"Enter Singer Name : "; getline(cin,new_song->singerName);
cout<<"Enter Song year : "; cin>>new_song->year;
cin.ignore();
if(head==NULL){
new_song->id=1;
head=new_song;
new_song->next=head;
tail=new_song;
new_song->prev=tail;
}else{
new_song->id=tail->id+1;
tail->next=new_song;
new_song->prev=tail;
new_song->next=head;
tail=new_song;
head->prev=tail;
}
}
void PlaySongs(int NumberOfCycles,bool IsPlayforward){
MyHitCollections*play;
if(IsPlayforward==true){ play=head;}
else{ play=tail;}
int count=0;
while(count!=NumberOfCycles){
if(IsPlayforward==true){
if(play->next==head){
count++;
}
}
else{
if(play->prev==tail){
count++;
}
}
cout<<"\nSong Played : "<<play->name<<" (year : "<<play->year<<")\n";
if(IsPlayforward==true){
play=play->next;
}
else{
play=play->prev;
}
}
}
void search(int year){
MyHitCollections*toSearch;
toSearch=head;
bool check=false;
while(1){
if(toSearch->year==year){
cout<<"ID : "<<toSearch->id;
check=true;
break;
}
toSearch=toSearch->next;
if(toSearch==head){
break;
}
}
if(check==false){
cout<<"Song not found......\n";
}
}
int main(){
AddSong();
AddSong();
AddSong();
search(2021);
PlaySongs(3,false);
}